1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-29 18:09:49 +02:00

Complete tests for selection and insertTextByKey

This commit is contained in:
Samy Pessé
2016-10-26 13:42:48 +02:00
parent 53d355511f
commit e08ef88d54
15 changed files with 86 additions and 0 deletions

View File

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

View File

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

View File

@@ -0,0 +1,30 @@
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const firstText = texts.first()
const nextSelection = selection.merge({
anchorKey: firstText.key,
focusKey: firstText.key,
anchorOffset: 2,
focusOffset: 4
})
const next = state
.transform()
.moveTo(nextSelection)
.insertTextByKey(firstText.key, 2, 'XX')
.apply()
assert.deepEqual(
next.selection.toJS(),
nextSelection.merge({
focusOffset: 6
}).toJS()
)
return next
}

View File

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

View File

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

View File

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