Skip to content

Commit

Permalink
Fix triple-click contenteditable="false" error (#5343)
Browse files Browse the repository at this point in the history
  • Loading branch information
12joan committed Mar 7, 2023
1 parent bc07cf8 commit f7f02a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-falcons-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

Fix error when triple-clicking a word preceding a `contenteditable="false"` DOM node in Chrome
11 changes: 11 additions & 0 deletions packages/slate-react/src/plugin/react-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f7f02a8

Please sign in to comment.