Skip to content

Commit

Permalink
Fix positions iteration when starting in an inline void node (ianstor…
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-codaio authored Apr 19, 2022
1 parent 34cfc1c commit 9ce0a08
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-plums-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate': patch
---

Fix positions iteration when starting inside an inline void node
3 changes: 3 additions & 0 deletions packages/slate/src/interfaces/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,9 @@ export const Editor: EditorInterface = {
// then we will iterate over their content.
if (!voids && editor.isVoid(node)) {
yield Editor.start(editor, path)
// It's possible the start of the range we're iterating over is in a void, in which case
// we want to make sure we don't incorrectly yield the start of a subsequent text node for unit !== 'offset'
isNewBlock = false
continue
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/** @jsx jsx */
import { Editor } from 'slate'
import { jsx } from '../../../..'

export const input = (
<editor>
<block>
one
<inline void>
<text />
</inline>
two
</block>
</editor>
)
export const test = editor => {
return Array.from(
Editor.positions(editor, {
at: {
anchor: { path: [0, 1, 0], offset: 0 },
focus: { path: [0, 2], offset: 2 },
},
unit: 'character',
})
)
}
export const output = [
{ path: [0, 1, 0], offset: 0 },
{ path: [0, 2], offset: 1 },
{ path: [0, 2], offset: 2 },
]

0 comments on commit 9ce0a08

Please sign in to comment.