1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-07-31 20:40:19 +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 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 end = Editor.end(editor, [path[0]])
const range = Editor.range(editor, start, end)
@@ -772,27 +784,18 @@ export const Editable = (props: EditableProps) => {
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 end = Editor.end(editor, path)
const startVoid = Editor.void(editor, { at: start })
const endVoid = Editor.void(editor, { at: end })
const start = Editor.start(editor, path)
const end = Editor.end(editor, path)
const startVoid = Editor.void(editor, { at: start })
const endVoid = Editor.void(editor, { at: end })
if (
startVoid &&
endVoid &&
Path.equals(startVoid[1], endVoid[1])
) {
const range = Editor.range(editor, start)
Transforms.select(editor, range)
}
}
if (
startVoid &&
endVoid &&
Path.equals(startVoid[1], endVoid[1])
) {
const range = Editor.range(editor, start)
Transforms.select(editor, range)
}
}
},