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:
@@ -253,7 +253,6 @@ function removeNode(state, operation) {
|
|||||||
.takeUntil(text => text.key == startKey)
|
.takeUntil(text => text.key == startKey)
|
||||||
.filter(text => !getRemoved(text.key))
|
.filter(text => !getRemoved(text.key))
|
||||||
.last()
|
.last()
|
||||||
|
|
||||||
if (!prevText) selection = selection.unset()
|
if (!prevText) selection = selection.unset()
|
||||||
else selection = selection.moveStartTo(prevText.key, prevText.length)
|
else selection = selection.moveStartTo(prevText.key, prevText.length)
|
||||||
}
|
}
|
||||||
|
@@ -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
|
||||||
|
}
|
@@ -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
|
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
nodes:
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: hello
|
Reference in New Issue
Block a user