1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-01-17 13:38:37 +01:00

Fix triple-click contenteditable="false" error (#5343)

This commit is contained in:
Joe Anderson 2023-03-07 17:15:59 +00:00 committed by GitHub
parent bc07cf8c86
commit f7f02a8b23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
'slate-react': patch
---
Fix error when triple-clicking a word preceding a `contenteditable="false"` DOM node in Chrome

View File

@ -754,6 +754,17 @@ export const ReactEditor = {
)
}
// COMPAT: Triple-clicking a word in chrome will sometimes place the focus
// inside a `contenteditable="false"` DOM node following the word, which
// will cause `toSlatePoint` to throw an error. (2023/03/07)
if (
'getAttribute' in focusNode &&
(focusNode as HTMLElement).getAttribute('contenteditable') === 'false'
) {
focusNode = anchorNode
focusOffset = anchorNode.textContent?.length || 0
}
let anchor = ReactEditor.toSlatePoint(editor, [anchorNode, anchorOffset], {
exactMatch,
suppressThrow,