mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 14:41:23 +02:00
Add test for inserting text before selection
This commit is contained in:
@@ -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: 2
|
||||
})
|
||||
|
||||
const next = state
|
||||
.transform()
|
||||
.moveTo(nextSelection)
|
||||
.insertTextByKey(firstText.key, 0, 'XX')
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(
|
||||
next.selection.toJS(),
|
||||
nextSelection.merge({
|
||||
anchorOffset: 4,
|
||||
focusOffset: 4
|
||||
}).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: XXhello
|
@@ -20,10 +20,10 @@ export default function (state) {
|
||||
.insertTextByKey(secondText.key, 5, 'X')
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(
|
||||
next.selection.toJS(),
|
||||
nextSelection.toJS()
|
||||
)
|
||||
assert.deepEqual(
|
||||
next.selection.toJS(),
|
||||
nextSelection.toJS()
|
||||
)
|
||||
|
||||
return next
|
||||
}
|
||||
|
@@ -20,10 +20,10 @@ export default function (state) {
|
||||
.insertTextByKey(secondText.key, 2, 'XX', [ { type: 'bold' } ])
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(
|
||||
next.selection.toJS(),
|
||||
nextSelection.toJS()
|
||||
)
|
||||
assert.deepEqual(
|
||||
next.selection.toJS(),
|
||||
nextSelection.toJS()
|
||||
)
|
||||
|
||||
return next
|
||||
}
|
||||
|
@@ -20,10 +20,10 @@ export default function (state) {
|
||||
.insertTextByKey(secondText.key, 2, 'X')
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(
|
||||
next.selection.toJS(),
|
||||
nextSelection.toJS()
|
||||
)
|
||||
assert.deepEqual(
|
||||
next.selection.toJS(),
|
||||
nextSelection.toJS()
|
||||
)
|
||||
|
||||
return next
|
||||
}
|
||||
|
@@ -20,10 +20,10 @@ export default function (state) {
|
||||
.insertTextByKey(secondText.key, 0, 'X')
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(
|
||||
next.selection.toJS(),
|
||||
nextSelection.toJS()
|
||||
)
|
||||
assert.deepEqual(
|
||||
next.selection.toJS(),
|
||||
nextSelection.toJS()
|
||||
)
|
||||
|
||||
return next
|
||||
}
|
||||
|
Reference in New Issue
Block a user