1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-04-15 10:52:34 +02:00

Add tests for Editor.unhangRange() (#4703)

* Add tests for Editor.unhangRange()

* Extend tests for `Editor.unhangRange()` to cover voids

* Fix lint

* Add changeset
This commit is contained in:
Ivan Voskoboinyk 2021-12-22 14:02:50 +02:00 committed by GitHub
parent e5427dddfc
commit 205d4b7e66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 179 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
'slate': patch
---
Add tests for Editor.unhangRange() behavior

View File

@ -0,0 +1,26 @@
/** @jsx jsx */
import { Editor } from 'slate'
import { jsx } from '../../..'
export const input = (
<editor>
<block>
<anchor />
This is a first paragraph
</block>
<block>This is the second paragraph</block>
<block void />
<block>
<focus />
</block>
</editor>
)
export const test = editor => {
return Editor.unhangRange(editor, editor.selection, { voids: true })
}
export const output = {
anchor: { path: [0, 0], offset: 0 },
focus: { path: [1, 0], offset: 28 },
}

View File

@ -0,0 +1,26 @@
/** @jsx jsx */
import { Editor } from 'slate'
import { jsx } from '../../..'
export const input = (
<editor>
<block>
<anchor />
This is a first paragraph
</block>
<block>This is the second paragraph</block>
<block void />
<block>
<focus />
</block>
</editor>
)
export const test = editor => {
return Editor.unhangRange(editor, editor.selection)
}
export const output = {
anchor: { path: [0, 0], offset: 0 },
focus: { path: [1, 0], offset: 28 },
}

View File

@ -0,0 +1,25 @@
/** @jsx jsx */
import { Editor } from 'slate'
import { jsx } from '../../..'
export const input = (
<editor>
<block>
<anchor />
word
</block>
<block>
<focus />
another
</block>
</editor>
)
export const test = editor => {
return Editor.unhangRange(editor, editor.selection)
}
export const output = {
anchor: { path: [0, 0], offset: 0 },
focus: { path: [0, 0], offset: 4 },
}

View File

@ -0,0 +1,19 @@
/** @jsx jsx */
import { Editor } from 'slate'
import { jsx } from '../../..'
export const input = (
<editor>
<block>
one
<cursor />
</block>
</editor>
)
export const test = editor => {
return Editor.unhangRange(editor, editor.selection)
}
export const output = {
anchor: { path: [0, 0], offset: 3 },
focus: { path: [0, 0], offset: 3 },
}

View File

@ -0,0 +1,28 @@
/** @jsx jsx */
import { Editor } from 'slate'
import { jsx } from '../../..'
export const input = (
<editor>
<block>
<text>
before
<anchor />
</text>
<text>selected</text>
<text>
<focus />
after
</text>
</block>
</editor>
)
export const test = editor => {
return Editor.unhangRange(editor, editor.selection)
}
export const output = {
anchor: { path: [0, 0], offset: 6 },
focus: { path: [0, 2], offset: 0 },
}

View File

@ -0,0 +1,25 @@
/** @jsx jsx */
import { Editor } from 'slate'
import { jsx } from '../../..'
export const input = (
<editor>
<block>
<anchor />
This is a first paragraph
</block>
<block>This is the second paragraph</block>
<block void>
<focus />
</block>
</editor>
)
export const test = editor => {
return Editor.unhangRange(editor, editor.selection, { voids: true })
}
export const output = {
anchor: { path: [0, 0], offset: 0 },
focus: { path: [1, 0], offset: 28 },
}

View File

@ -0,0 +1,25 @@
/** @jsx jsx */
import { Editor } from 'slate'
import { jsx } from '../../..'
export const input = (
<editor>
<block>
<anchor />
This is a first paragraph
</block>
<block>This is the second paragraph</block>
<block void>
<focus />
</block>
</editor>
)
export const test = editor => {
return Editor.unhangRange(editor, editor.selection)
}
export const output = {
anchor: { path: [0, 0], offset: 0 },
focus: { path: [0, 0], offset: 25 },
}