1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 10:29:48 +02:00

Add more tests for removeTextByKey

This commit is contained in:
Samy Pessé
2016-10-26 14:57:06 +02:00
parent 99e9a77639
commit 29afc577b0
12 changed files with 180 additions and 0 deletions

View File

@@ -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)
.removeTextByKey(firstText.key, 0, 1)
.apply()
assert.deepEqual(
next.selection.toJS(),
nextSelection.merge({
anchorOffset: 1,
focusOffset: 1
}).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: ello

View File

@@ -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)
.removeTextByKey(firstText.key, 3, 1)
.apply()
assert.deepEqual(
next.selection.toJS(),
nextSelection.merge({
anchorOffset: 2,
focusOffset: 2
}).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: helo

View File

@@ -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: 3,
focusOffset: 3
})
const next = state
.transform()
.moveTo(nextSelection)
.removeTextByKey(firstText.key, 2, 1)
.apply()
assert.deepEqual(
next.selection.toJS(),
nextSelection.merge({
anchorOffset: 2,
focusOffset: 2
}).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: helo

View File

@@ -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: 1,
focusOffset: 5
})
const next = state
.transform()
.moveTo(nextSelection)
.removeTextByKey(firstText.key, 2, 1)
.apply()
assert.deepEqual(
next.selection.toJS(),
nextSelection.merge({
anchorOffset: 1,
focusOffset: 4
}).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: helo