1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-11 09:43:58 +02:00

Fix editor root tripple click crash (#4944)

This commit is contained in:
Eric Meier
2022-04-13 19:58:12 +02:00
committed by GitHub
parent 0e598ab229
commit 486c385bc5
2 changed files with 29 additions and 21 deletions

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
Fix crash when tripple clicking editor root

View File

@@ -760,7 +760,19 @@ export const Editable = (props: EditableProps) => {
) { ) {
const node = ReactEditor.toSlateNode(editor, event.target) const node = ReactEditor.toSlateNode(editor, event.target)
const path = ReactEditor.findPath(editor, node) const path = ReactEditor.findPath(editor, node)
if (event.detail === TRIPLE_CLICK) {
// At this time, the Slate document may be arbitrarily different,
// because onClick handlers can change the document before we get here.
// Therefore we must check that this path actually exists,
// and that it still refers to the same node.
if (
!Editor.hasPath(editor, path) ||
Node.get(editor, path) !== node
) {
return
}
if (event.detail === TRIPLE_CLICK && path.length >= 1) {
const start = Editor.start(editor, [path[0]]) const start = Editor.start(editor, [path[0]])
const end = Editor.end(editor, [path[0]]) const end = Editor.end(editor, [path[0]])
const range = Editor.range(editor, start, end) const range = Editor.range(editor, start, end)
@@ -772,13 +784,6 @@ export const Editable = (props: EditableProps) => {
return return
} }
// At this time, the Slate document may be arbitrarily different,
// because onClick handlers can change the document before we get here.
// Therefore we must check that this path actually exists,
// and that it still refers to the same node.
if (Editor.hasPath(editor, path)) {
const lookupNode = Node.get(editor, path)
if (lookupNode === node) {
const start = Editor.start(editor, path) const start = Editor.start(editor, path)
const end = Editor.end(editor, path) const end = Editor.end(editor, path)
const startVoid = Editor.void(editor, { at: start }) const startVoid = Editor.void(editor, { at: start })
@@ -793,8 +798,6 @@ export const Editable = (props: EditableProps) => {
Transforms.select(editor, range) Transforms.select(editor, range)
} }
} }
}
}
}, },
[readOnly, attributes.onClick] [readOnly, attributes.onClick]
)} )}