mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-30 02:19:52 +02:00
Fix bug: setting selection from contentEditable:false element causes crash
Fixes https://github.com/ianstormtaylor/slate/issues/4583 When clicking some text in a `contentEditable:false` element, if the handler for this sets the selection, Slate crashes. Slate tries to find a Slate range for the text that was clicked on, but there is no such range, because the text is inside a `contentEditable:false` element. Slate seems to be making a bad assumption that the current DOM selection necessarily corresponds to a Slate range, but this is not the case if the user just clicked into an element with `contentEditable: false`. To fix this, I changed `exactMatch: false` to `exactMatch: true`, which seems to mean "fail gracefully if there is no exact match".
This commit is contained in:
@@ -182,7 +182,9 @@ export const Editable = (props: EditableProps) => {
|
||||
// If the DOM selection is in the editor and the editor selection is already correct, we're done.
|
||||
if (hasDomSelection && hasDomSelectionInEditor && selection) {
|
||||
const slateRange = ReactEditor.toSlateRange(editor, domSelection, {
|
||||
exactMatch: false,
|
||||
// domSelection is not necessarily a valid Slate range
|
||||
// (e.g. when clicking on contentEditable:false element)
|
||||
exactMatch: true
|
||||
})
|
||||
if (slateRange && Range.equals(slateRange, selection)) {
|
||||
return
|
||||
|
Reference in New Issue
Block a user