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:
5
.changeset/poor-mangos-burn.md
Normal file
5
.changeset/poor-mangos-burn.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Prevent native insert at the end of anchor elements
|
@@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user