Feat: editable dom element (#39341)

* feat: __testEditable allows editable region tests

It's not entirely isolated, but it makes it possible to select only the
element with id 'editable-only' which is built solely from code inside
the editable region.

* fix(client): missing editableContents -> ''

Previously it was added as the string 'undefined'

* fix: more informative error messages

* fix: DRY, correct and test getLines
This commit is contained in:
Oliver Eyton-Williams
2020-08-17 03:57:52 +02:00
committed by Mrugesh Mohapatra
parent a1a051bd3a
commit 9df098953d
6 changed files with 106 additions and 36 deletions

16
utils/get-lines.js Normal file
View File

@ -0,0 +1,16 @@
const { isEmpty } = require('lodash');
// TODO: secure with tests
function getLines(contents, range) {
if (isEmpty(range)) {
return '';
}
const lines = contents.split('\n');
const editableLines =
isEmpty(lines) || range[1] <= range[0]
? []
: lines.slice(range[0], range[1] - 1);
return editableLines.join('\n');
}
exports.getLines = getLines;