mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-07 15:56:35 +02:00
Fix for Editor.positions not working correctly in all cases (#4073)
* fixed bug with Editor.positions slicing beyond the available characters in the current text node * fixed issues with line and word Editor.positions on fragmented text * renamed some of the tests and added some more
This commit is contained in:
@@ -1295,8 +1295,8 @@ export const Editor: EditorInterface = {
|
||||
}
|
||||
|
||||
while (true) {
|
||||
// If there's no more string, continue to the next block.
|
||||
if (string === '') {
|
||||
// If there's no more string and there is no more characters to skip, continue to the next block.
|
||||
if (string === '' && distance === null) {
|
||||
break
|
||||
} else {
|
||||
advance()
|
||||
|
@@ -0,0 +1,29 @@
|
||||
/** @jsx jsx */
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
<text />
|
||||
<inline>
|
||||
<text />
|
||||
<inline>
|
||||
<text />
|
||||
</inline>
|
||||
<text />
|
||||
</inline>
|
||||
<text />
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const test = editor => {
|
||||
return Array.from(Editor.positions(editor, { at: [] }))
|
||||
}
|
||||
export const output = [
|
||||
{ path: [0, 0], offset: 0 },
|
||||
{ path: [0, 1, 0], offset: 0 },
|
||||
{ path: [0, 1, 1, 0], offset: 0 },
|
||||
{ path: [0, 1, 2], offset: 0 },
|
||||
{ path: [0, 2], offset: 0 },
|
||||
]
|
@@ -0,0 +1,23 @@
|
||||
/** @jsx jsx */
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
1<inline>2</inline>3
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const test = editor => {
|
||||
return Array.from(Editor.positions(editor, { at: [], reverse: true }))
|
||||
}
|
||||
|
||||
export const output = [
|
||||
{ path: [0, 2], offset: 1 },
|
||||
{ path: [0, 2], offset: 0 },
|
||||
{ path: [0, 1, 0], offset: 1 },
|
||||
{ path: [0, 1, 0], offset: 0 },
|
||||
{ path: [0, 0], offset: 1 },
|
||||
{ path: [0, 0], offset: 0 },
|
||||
]
|
@@ -0,0 +1,23 @@
|
||||
/** @jsx jsx */
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
1<inline>2</inline>3
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const test = editor => {
|
||||
return Array.from(Editor.positions(editor, { at: [] }))
|
||||
}
|
||||
|
||||
export const output = [
|
||||
{ path: [0, 0], offset: 0 },
|
||||
{ path: [0, 0], offset: 1 },
|
||||
{ path: [0, 1, 0], offset: 0 },
|
||||
{ path: [0, 1, 0], offset: 1 },
|
||||
{ path: [0, 2], offset: 0 },
|
||||
{ path: [0, 2], offset: 1 },
|
||||
]
|
@@ -0,0 +1,21 @@
|
||||
/** @jsx jsx */
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
😀<inline>😀</inline>😀
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const test = editor => {
|
||||
return Array.from(Editor.positions(editor, { at: [], unit: 'character' }))
|
||||
}
|
||||
|
||||
export const output = [
|
||||
{ path: [0, 0], offset: 0 },
|
||||
{ path: [0, 0], offset: 2 },
|
||||
{ path: [0, 1, 0], offset: 2 },
|
||||
{ path: [0, 2], offset: 2 },
|
||||
]
|
@@ -0,0 +1,23 @@
|
||||
/** @jsx jsx */
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
1<inline>2</inline>3
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const test = editor => {
|
||||
return Array.from(
|
||||
Editor.positions(editor, { at: [], unit: 'character', reverse: true })
|
||||
)
|
||||
}
|
||||
|
||||
export const output = [
|
||||
{ path: [0, 2], offset: 1 },
|
||||
{ path: [0, 2], offset: 0 },
|
||||
{ path: [0, 1, 0], offset: 0 },
|
||||
{ path: [0, 0], offset: 0 },
|
||||
]
|
@@ -0,0 +1,21 @@
|
||||
/** @jsx jsx */
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
1<inline>2</inline>3
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const test = editor => {
|
||||
return Array.from(Editor.positions(editor, { at: [], unit: 'character' }))
|
||||
}
|
||||
|
||||
export const output = [
|
||||
{ path: [0, 0], offset: 0 },
|
||||
{ path: [0, 0], offset: 1 },
|
||||
{ path: [0, 1, 0], offset: 1 },
|
||||
{ path: [0, 2], offset: 1 },
|
||||
]
|
@@ -0,0 +1,21 @@
|
||||
/** @jsx jsx */
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
he<inline>ll</inline>o wo<inline>rl</inline>d
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const test = editor => {
|
||||
return Array.from(
|
||||
Editor.positions(editor, { at: [], unit: 'line', reverse: true })
|
||||
)
|
||||
}
|
||||
|
||||
export const output = [
|
||||
{ path: [0, 4], offset: 1 },
|
||||
{ path: [0, 0], offset: 0 },
|
||||
]
|
@@ -0,0 +1,19 @@
|
||||
/** @jsx jsx */
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
he<inline>ll</inline>o wo<inline>rl</inline>d
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const test = editor => {
|
||||
return Array.from(Editor.positions(editor, { at: [], unit: 'line' }))
|
||||
}
|
||||
|
||||
export const output = [
|
||||
{ path: [0, 0], offset: 0 },
|
||||
{ path: [0, 4], offset: 1 },
|
||||
]
|
@@ -0,0 +1,20 @@
|
||||
/** @jsx jsx */
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>
|
||||
he<inline>ll</inline>o wo<inline>rl</inline>d
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const test = editor => {
|
||||
return Array.from(Editor.positions(editor, { at: [], unit: 'word' }))
|
||||
}
|
||||
|
||||
export const output = [
|
||||
{ path: [0, 0], offset: 0 },
|
||||
{ path: [0, 2], offset: 1 },
|
||||
{ path: [0, 4], offset: 1 },
|
||||
]
|
Reference in New Issue
Block a user