1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-17 20:51:20 +02:00

add toggleMarkAtRange remove tests

This commit is contained in:
Ian Storm Taylor
2016-07-21 12:26:11 -07:00
parent 4d69df224a
commit 00261eded9
27 changed files with 402 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const second = texts.last()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 2,
focusKey: second.key,
focusOffset: 2
})
return state
.transform()
.toggleMarkAtRange(range, 'bold')
.apply()
}

View File

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

View File

@@ -0,0 +1,20 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: wo
marks:
- type: bold
- text: rd
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: an
- text: other
marks:
- type: bold

View File

@@ -0,0 +1,18 @@
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const second = texts.last()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 2,
focusKey: second.key,
focusOffset: 2
})
return state
.transform()
.toggleMarkAtRange(range, 'bold')
.apply()
}

View File

@@ -0,0 +1,24 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: word
marks:
- type: bold
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: another
marks:
- type: bold

View File

@@ -0,0 +1,26 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: wo
marks:
- type: bold
- text: rd
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: an
- text: other
marks:
- type: bold

View File

@@ -0,0 +1,17 @@
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 2
})
return state
.transform()
.toggleMarkAtRange(range, 'bold')
.apply()
}

View File

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

View File

@@ -0,0 +1,14 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: wo
marks:
- type: italic
- text: rd
marks:
- type: italic
- type: bold

View File

@@ -0,0 +1,17 @@
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 1
})
return state
.transform()
.toggleMarkAtRange(range, 'bold')
.apply()
}

View File

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

View File

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

View File

@@ -0,0 +1,17 @@
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 - 1,
focusKey: first.key,
focusOffset: first.length
})
return state
.transform()
.toggleMarkAtRange(range, 'bold')
.apply()
}

View File

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

View File

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

View File

@@ -0,0 +1,17 @@
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 1,
focusKey: first.key,
focusOffset: 2
})
return state
.transform()
.toggleMarkAtRange(range, 'bold')
.apply()
}

View File

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

View File

@@ -0,0 +1,14 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: w
marks:
- type: bold
- text: o
- text: rd
marks:
- type: bold

View File

@@ -0,0 +1,17 @@
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: first.length
})
return state
.transform()
.toggleMarkAtRange(range, 'bold')
.apply()
}

View File

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

View File

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

View File

@@ -0,0 +1,22 @@
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: 0,
focusKey: first.key,
focusOffset: 1
})
return state
.transform()
.toggleMarkAtRange(range, Mark.create({
type: 'bold',
data: { key: 'value' }
}))
.apply()
}

View File

@@ -0,0 +1,13 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: w
marks:
- type: bold
data:
key: value
- text: ord

View File

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

View File

@@ -0,0 +1,20 @@
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 1
})
return state
.transform()
.toggleMarkAtRange(range, {
type: 'bold',
data: { key: 'value' }
})
.apply()
}

View File

@@ -0,0 +1,13 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: w
marks:
- type: bold
data:
key: value
- text: ord

View File

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