1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-24 16:02:55 +02:00

Adapt existing tests

This commit is contained in:
Soreine
2016-10-26 14:48:24 +02:00
parent a50d381d8e
commit b3e1b3ad08
10 changed files with 53 additions and 33 deletions

View File

@@ -2,14 +2,11 @@
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
let first = texts.first()
const second = texts.last()
const { selection } = state
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 2,
focusKey: second.key,
anchorKey: 'anchor',
anchorOffset: 1,
focusKey: 'focus',
focusOffset: 2
})
@@ -19,15 +16,18 @@ export default function (state) {
.unwrapInline('hashtag')
.apply()
// Selection is reset, in theory it should me on the image
first = next.document.getTexts().first()
// Test selection
const { document } = next
const first = document.getTexts().first()
const last = document.getTexts().last()
assert.deepEqual(
next.selection.toJS(),
range.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 0
anchorOffset: 1,
focusKey: last.key,
focusOffset: 4
}).toJS()
)

View File

@@ -4,6 +4,7 @@ nodes:
type: paragraph
nodes:
- kind: text
key: 'anchor' # w[o
text: wo
- kind: inline
type: hashtag
@@ -19,4 +20,5 @@ nodes:
- kind: text
text: an
- kind: text
key: 'focus' # ot]her
text: other

View File

@@ -10,3 +10,5 @@ nodes:
nodes:
- kind: text
text: another
# Selection
# w[ordanot]her

View File

@@ -2,14 +2,11 @@
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const last = texts.get(1)
const { selection } = state
const range = selection.merge({
anchorKey: first.key,
anchorKey: 'anchor',
anchorOffset: 1,
focusKey: last.key,
focusKey: 'focus',
focusOffset: 2
})
@@ -21,7 +18,10 @@ export default function (state) {
assert.deepEqual(
next.selection.toJS(),
range.collapseToStartOf(next.document).toJS()
range.merge({
focusKey: 'anchor',
focusOffset: 3
}).toJS()
)
return next

View File

@@ -7,11 +7,15 @@ nodes:
type: paragraph
nodes:
- kind: text
key: 'anchor'
text: w
- kind: inline
type: hashtag
nodes:
- kind: text
key: 'focus'
text: or
- kind: text
text: d
# Selection
# w[or]d

View File

@@ -2,14 +2,11 @@
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.get(2)
const last = texts.get(3)
const { selection } = state
const range = selection.merge({
anchorKey: first.key,
anchorKey: 'anchor',
anchorOffset: 2,
focusKey: last.key,
focusKey: 'focus',
focusOffset: 2
})
@@ -21,7 +18,10 @@ export default function (state) {
assert.deepEqual(
next.selection.toJS(),
range.collapseToStartOf(next.document).toJS()
range.merge({
focusKey: 'anchor',
focusOffset: 5
}).toJS()
)
return next

View File

@@ -11,11 +11,16 @@ nodes:
- kind: text
text: ll
- kind: text
key: 'anchor'
text: "o w"
- kind: inline
type: hashtag
nodes:
- kind: text
key: 'focus'
text: or
- kind: text
text: d
# Selection
# hello [wor]d

View File

@@ -12,3 +12,5 @@ nodes:
text: ll
- kind: text
text: "o word"
# Selection
# hello [wor]d

View File

@@ -2,14 +2,11 @@
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const last = texts.get(1)
const { selection } = state
const range = selection.merge({
anchorKey: first.key,
anchorKey: 'anchor',
anchorOffset: 1,
focusKey: last.key,
focusKey: 'focus',
focusOffset: 2
})
@@ -21,7 +18,10 @@ export default function (state) {
assert.deepEqual(
next.selection.toJS(),
range.collapseToStartOf(next.document).toJS()
range.merge({
focusKey: 'anchor',
focusOffset: 3
}).toJS()
)
return next

View File

@@ -4,11 +4,16 @@ nodes:
type: paragraph
nodes:
- kind: text
key: 'anchor'
text: w
- kind: inline
type: hashtag
nodes:
- kind: text
key: 'focus'
text: or
- kind: text
text: d
# selection:
# w[or]d