diff --git a/lib/models/node.js b/lib/models/node.js index e6c078599..5d3046374 100644 --- a/lib/models/node.js +++ b/lib/models/node.js @@ -63,12 +63,9 @@ const Node = { // If the start and end nodes are the same, just remove characters. if (startKey == endKey) { - const startNode = node.getDescendant(startKey) - const characters = startNode.characters.filterNot((char, i) => { - return startOffset <= i && i < endOffset - }) - - node = node.updateDescendant(startNode.merge({ characters })) + let text = node.getDescendant(startKey) + text = text.removeCharacters(startOffset, endOffset) + node = node.updateDescendant(text) return node } diff --git a/lib/models/text.js b/lib/models/text.js index a779467f3..47a7c7b33 100644 --- a/lib/models/text.js +++ b/lib/models/text.js @@ -22,7 +22,7 @@ class Text extends Record(DEFAULTS) { * Create a new `Text` with `properties`. * * @param {Object} properties - * @return {Node} node + * @return {Text} text */ static create(properties = {}) { @@ -64,6 +64,24 @@ class Text extends Record(DEFAULTS) { .join('') } + /** + * Remove characters from the text node from `start` to `end`. + * + * @param {Number} start + * @param {Number} end + * @return {Text} text + */ + + removeCharacters(start, end) { + let { characters } = this + + characters = characters.filterNot((char, i) => { + return start <= i && i < end + }) + + return this.merge({ characters }) + } + } /**