1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-12 10:14:02 +02:00

Prevent native insert at the end of anchors (#4948)

* Prevent native insert at the end of anchors

* add changeset
This commit is contained in:
Eric Meier
2022-04-18 12:39:45 -04:00
committed by GitHub
parent 5160efeea4
commit 9957c21435
2 changed files with 17 additions and 11 deletions

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
Prevent native insert at the end of anchor elements

View File

@@ -368,19 +368,20 @@ export const Editable = (props: EditableProps) => {
native = false native = false
} }
// Chrome also has issues correctly editing the end of nodes: https://bugs.chromium.org/p/chromium/issues/detail?id=1259100 // Chrome also has issues correctly editing the end of anchor elements: https://bugs.chromium.org/p/chromium/issues/detail?id=1259100
// Therefore we don't allow native events to insert text at the end of nodes. // Therefore we don't allow native events to insert text at the end of anchor nodes.
const { anchor } = selection const { anchor } = selection
const inline = Editor.above(editor, { if (Editor.isEnd(editor, anchor, anchor.path)) {
at: anchor, const [node] = ReactEditor.toDOMPoint(editor, selection.anchor)
match: n => Editor.isInline(editor, n), const anchorNode = node.parentElement?.closest('a')
mode: 'highest',
})
if (inline) {
const [, inlinePath] = inline
if (Editor.isEnd(editor, selection.anchor, inlinePath)) { if (anchorNode && ReactEditor.hasDOMNode(editor, anchorNode)) {
native = false const node = ReactEditor.toSlateNode(editor, anchorNode)
const path = ReactEditor.findPath(editor, node)
if (Editor.isEnd(editor, anchor, path)) {
native = false
}
} }
} }
} }