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:
@@ -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()
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: word
|
@@ -0,0 +1,11 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: word
|
||||
- text: a
|
||||
marks:
|
||||
- type: bold
|
34
test/transforms/fixtures/insert-text/with-marks/index.js
Normal file
34
test/transforms/fixtures/insert-text/with-marks/index.js
Normal 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
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: word
|
11
test/transforms/fixtures/insert-text/with-marks/output.yaml
Normal file
11
test/transforms/fixtures/insert-text/with-marks/output.yaml
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: word
|
||||
- text: a
|
||||
marks:
|
||||
- type: bold
|
Reference in New Issue
Block a user