Skip to content

Commit 498e0ac

Browse files
committed
Fix Slate error when deselecting text in Chrome
When selecting text right-to-left and clicking outside the contenteditable to deselect, Chrome triggers toSlateRange with a selection pointing outside the editor, causing an error. This workaround catches the error and returns the current editor selection, mimicking the upstream suppressThrow fix (ianstormtaylor/slate#4584).
1 parent d5eab43 commit 498e0ac

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

entry_types/scrolled/package/src/frontend/inlineEditing/EditableText/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {createEditor, Transforms, Node, Text as SlateText, Range} from 'slate';
44
import {Slate, Editable, withReact, ReactEditor} from 'slate-react';
55
import {withHistory} from 'slate-history';
66

7+
import '../slateFixes';
78
import {Text} from '../../Text';
89
import {useCachedValue} from '../useCachedValue';
910
import {useContentElementEditorCommandSubscription} from '../../useContentElementEditorCommandSubscription';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {ReactEditor} from 'slate-react';
2+
3+
const originalToSlateRange = ReactEditor.toSlateRange;
4+
5+
ReactEditor.toSlateRange = function(editor, domRange) {
6+
try {
7+
return originalToSlateRange.apply(this, arguments);
8+
} catch (e) {
9+
if (e.message.startsWith('Cannot resolve a Slate point from DOM point') &&
10+
domRange === window.getSelection() &&
11+
editor.selection) {
12+
console.warn('Ignored "Cannot resolve a Slate point from DOM point" - selection outside editor');
13+
return editor.selection;
14+
}
15+
16+
throw e;
17+
}
18+
}

0 commit comments

Comments
 (0)