1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-17 12:41:44 +02:00

Adapt selection in removeText operation

This commit is contained in:
Samy Pessé
2016-10-26 13:58:32 +02:00
parent e08ef88d54
commit 59583760f2

View File

@@ -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
}