Skip to content

Commit

Permalink
fix(core): fix error when triple-clicking a word preceding a `content…
Browse files Browse the repository at this point in the history
…editable="false"` DOM node in Chrome #186
  • Loading branch information
pubuzhixing8 committed Feb 3, 2024
1 parent 1c34226 commit 4ef6370
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/happy-dancers-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"slate-angular": patch
---

Fix error when triple-clicking a word preceding a `contenteditable="false"` DOM node in Chrome
refer to: https://github.com/ianstormtaylor/slate/pull/5343
12 changes: 12 additions & 0 deletions packages/src/plugins/angular-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,18 @@ export const AngularEditor = {
throw new Error(`Cannot resolve a Slate range from DOM range: ${domRange}`);
}

// 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 as HTMLElement).getAttribute('data-slate-void') !== 'true'
) {
focusNode = anchorNode;
focusOffset = anchorNode.textContent?.length || 0;
}

const anchor = AngularEditor.toSlatePoint(editor, [anchorNode, anchorOffset]);
const focus = isCollapsed ? anchor : AngularEditor.toSlatePoint(editor, [focusNode, focusOffset]);

Expand Down

0 comments on commit 4ef6370

Please sign in to comment.