1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-27 09:04:31 +02:00

Add test for selection inside a removeNodeByKey

This commit is contained in:
Samy Pessé
2016-10-26 17:25:20 +02:00
parent f84f9fd1ef
commit 440aebb685
4 changed files with 54 additions and 1 deletions

View File

@@ -253,7 +253,6 @@ function removeNode(state, operation) {
.takeUntil(text => text.key == startKey)
.filter(text => !getRemoved(text.key))
.last()
if (!prevText) selection = selection.unset()
else selection = selection.moveStartTo(prevText.key, prevText.length)
}

View File

@@ -0,0 +1,34 @@
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const firstText = texts.first()
const secondText = texts.get(1)
const nextSelection = selection.merge({
anchorKey: secondText.key,
focusKey: secondText.key,
anchorOffset: 2,
focusOffset: 2
})
const next = state
.transform()
.moveTo(nextSelection)
.removeNodeByKey('todelete')
.apply()
assert.deepEqual(
next.selection.toJS(),
nextSelection.merge({
anchorKey: firstText.key,
focusKey: firstText.key,
anchorOffset: 5,
focusOffset: 5
}).toJS()
)
return next
}

View File

@@ -0,0 +1,13 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: hello
- kind: block
key: todelete
type: paragraph
nodes:
- kind: text
text: removed

View File

@@ -0,0 +1,7 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: hello