Skip to content

Commit

Permalink
Do not move selection outside inline node when composition starts
Browse files Browse the repository at this point in the history
  • Loading branch information
12joan committed Oct 27, 2023
1 parent 0bdff51 commit d8335a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-tools-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

Do not move selection outside inline node when composition starts
23 changes: 3 additions & 20 deletions packages/slate-react/src/components/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1190,26 +1190,9 @@ export const Editable = (props: EditableProps) => {
setIsComposing(true)

const { selection } = editor
if (selection) {
if (Range.isExpanded(selection)) {
Editor.deleteFragment(editor)
return
}
const inline = Editor.above(editor, {
match: n =>
Element.isElement(n) && Editor.isInline(editor, n),
mode: 'highest',
})
if (inline) {
const [, inlinePath] = inline
if (Editor.isEnd(editor, selection.anchor, inlinePath)) {
const point = Editor.after(editor, inlinePath)!
Transforms.setSelection(editor, {
anchor: point,
focus: point,
})
}
}
if (selection && Range.isExpanded(selection)) {
Editor.deleteFragment(editor)
return
}
}
},
Expand Down

0 comments on commit d8335a6

Please sign in to comment.