mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-29 09:59:48 +02:00
Add unit test for selection in insertText
This commit is contained in:
@@ -7,10 +7,10 @@ export default function (state) {
|
||||
const firstText = texts.first()
|
||||
|
||||
const nextSelection = selection.merge({
|
||||
anchorKey: firstText.key,
|
||||
focusKey: firstText.key,
|
||||
anchorOffset: 2,
|
||||
focusOffset: 2
|
||||
anchorKey: firstText.key,
|
||||
focusKey: firstText.key,
|
||||
anchorOffset: 2,
|
||||
focusOffset: 2
|
||||
})
|
||||
|
||||
const next = state
|
||||
|
@@ -7,10 +7,10 @@ export default function (state) {
|
||||
const firstText = texts.first()
|
||||
|
||||
const nextSelection = selection.merge({
|
||||
anchorKey: firstText.key,
|
||||
focusKey: firstText.key,
|
||||
anchorOffset: 2,
|
||||
focusOffset: 2
|
||||
anchorKey: firstText.key,
|
||||
focusKey: firstText.key,
|
||||
anchorOffset: 2,
|
||||
focusOffset: 2
|
||||
})
|
||||
|
||||
const next = state
|
||||
|
@@ -8,10 +8,10 @@ export default function (state) {
|
||||
const secondText = texts.get(1)
|
||||
|
||||
const nextSelection = selection.merge({
|
||||
anchorKey: firstText.key,
|
||||
focusKey: firstText.key,
|
||||
anchorOffset: 2,
|
||||
focusOffset: 2
|
||||
anchorKey: firstText.key,
|
||||
focusKey: firstText.key,
|
||||
anchorOffset: 2,
|
||||
focusOffset: 2
|
||||
})
|
||||
|
||||
const next = state
|
||||
|
@@ -0,0 +1,31 @@
|
||||
|
||||
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, 3, 'XX')
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(
|
||||
next.selection.toJS(),
|
||||
nextSelection.merge({
|
||||
anchorOffset: 2,
|
||||
focusOffset: 6
|
||||
}).toJS()
|
||||
)
|
||||
|
||||
return next
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: hello
|
@@ -0,0 +1,7 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: helXXlo
|
@@ -8,10 +8,10 @@ export default function (state) {
|
||||
const secondText = texts.get(1)
|
||||
|
||||
const nextSelection = selection.merge({
|
||||
anchorKey: firstText.key,
|
||||
focusKey: firstText.key,
|
||||
anchorOffset: 2,
|
||||
focusOffset: 2
|
||||
anchorKey: firstText.key,
|
||||
focusKey: firstText.key,
|
||||
anchorOffset: 2,
|
||||
focusOffset: 2
|
||||
})
|
||||
|
||||
const next = state
|
||||
|
@@ -8,10 +8,10 @@ export default function (state) {
|
||||
const secondText = texts.get(1)
|
||||
|
||||
const nextSelection = selection.merge({
|
||||
anchorKey: firstText.key,
|
||||
focusKey: firstText.key,
|
||||
anchorOffset: 2,
|
||||
focusOffset: 2
|
||||
anchorKey: firstText.key,
|
||||
focusKey: firstText.key,
|
||||
anchorOffset: 2,
|
||||
focusOffset: 2
|
||||
})
|
||||
|
||||
const next = state
|
||||
|
@@ -8,10 +8,10 @@ export default function (state) {
|
||||
const secondText = texts.get(1)
|
||||
|
||||
const nextSelection = selection.merge({
|
||||
anchorKey: firstText.key,
|
||||
focusKey: firstText.key,
|
||||
anchorOffset: 2,
|
||||
focusOffset: 2
|
||||
anchorKey: firstText.key,
|
||||
focusKey: firstText.key,
|
||||
anchorOffset: 2,
|
||||
focusOffset: 2
|
||||
})
|
||||
|
||||
const next = state
|
||||
|
Reference in New Issue
Block a user