Skip to content

Commit

Permalink
UnhangRange considers void nodes
Browse files Browse the repository at this point in the history
- Include void node in range
- Add delete-void-at-end test
- Add delete-void-and-newline-at-end test
  • Loading branch information
songeunyou committed Dec 10, 2020
1 parent 912d4b7 commit 855e25f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
Binary file added .DS_Store
Binary file not shown.
9 changes: 8 additions & 1 deletion packages/slate/src/interfaces/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,13 @@ export const Editor = {
at: end,
match: n => Editor.isBlock(editor, n),
})

// If last element is a void node, unhang range by including void node in range
if (Editor.isVoid(editor, endBlock[0])) {
end = { path: end.path, offset: 1 }
return { anchor: start, focus: end }
}

const blockPath = endBlock ? endBlock[1] : []
const first = Editor.start(editor, [])
const before = { anchor: first, focus: end }
Expand All @@ -1274,7 +1281,7 @@ export const Editor = {
at: before,
match: Text.isText,
reverse: true,
voids,
voids: true,
})) {
if (skip) {
skip = false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/** @jsx jsx */
import { Editor, Transforms } from 'slate'
import { jsx } from '../../..'

export const input = (
<editor>
<block>
<text>
<anchor />
This is a first paragraph
</text>
</block>
<block>
<text>This is the second paragraph</text>
</block>
<block void>
<text />
</block>
<block>
<text>
<focus />
</text>
</block>
</editor>
)
export const run = editor => {
editor.deleteFragment(editor)
}
export const output = (
<editor>
<block>
<text>
<cursor />
</text>
</block>
<block>
<text />
</block>
</editor>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/** @jsx jsx */
import { Editor, Transforms } from 'slate'
import { jsx } from '../../..'

export const input = (
<editor>
<block>
<text>
<anchor />
This is a first paragraph
</text>
</block>
<block>
<text>This is the second paragraph</text>
</block>
<block void>
<text>
<focus />
</text>
</block>
</editor>
)
export const run = editor => {
editor.deleteFragment(editor)
}
export const output = (
<editor>
<block>
<text>
<cursor />
</text>
</block>
</editor>
)
Binary file added site/.DS_Store
Binary file not shown.

0 comments on commit 855e25f

Please sign in to comment.