From 59583760f2dede540fd93bdd19920b34c9ccad04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Wed, 26 Oct 2016 13:58:32 +0200 Subject: [PATCH] Adapt selection in removeText operation --- src/transforms/apply-operation.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/transforms/apply-operation.js b/src/transforms/apply-operation.js index ac578269c..2c0bb4052 100644 --- a/src/transforms/apply-operation.js +++ b/src/transforms/apply-operation.js @@ -219,11 +219,25 @@ function removeNode(state, operation) { function removeText(state, operation) { const { path, offset, length } = operation - let { document } = state + let { document, selection } = state + const { startKey, endKey, startOffset, endOffset } = selection let node = document.assertPath(path) + + const rangeOffset = offset + length + + // Update the document node = node.removeText(offset, length) document = document.updateDescendant(node) - state = state.merge({ document }) + + // Update the selection + if (startKey == node.key && startOffset >= rangeOffset) { + selection = selection.extendStartOffset(-length) + } + if (endKey == node.key && endOffset >= rangeOffset) { + selection = selection.extendEndOffset(-length) + } + + state = state.merge({ document, selection }) return state }