1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-31 19:01:54 +02:00

add tests for insertText with marks

This commit is contained in:
Ian Storm Taylor
2016-07-22 20:22:01 -07:00
parent 2a58f71c42
commit f8f01949e4
6 changed files with 97 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
import { Mark } from '../../../../..'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: first.length,
focusKey: first.key,
focusOffset: first.length
})
const marks = Mark.createSet([
Mark.create({
type: 'bold'
})
])
return state
.transform()
.insertTextAtRange(range, 'a', marks)
.apply()
}

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,11 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word
- text: a
marks:
- type: bold

View File

@@ -0,0 +1,34 @@
import { Mark } from '../../../../..'
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: first.length,
focusKey: first.key,
focusOffset: first.length
})
const marks = Mark.createSet([
Mark.create({
type: 'bold'
})
])
const next = state
.transform()
.moveTo(range)
.insertText('a', marks)
.apply()
assert.deepEqual(
next.selection.toJS(),
range.moveForward().toJS()
)
return next
}

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,11 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word
- text: a
marks:
- type: bold