1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-18 05:01:17 +02:00

Fix "Cannot resolve from DOM point" error on onDomSelectionChange for readonly void elements (#4727)

* fix error caused by selecting void nodes in readonly editor

* add changeset
This commit is contained in:
Alex
2021-12-10 13:52:03 +01:00
committed by GitHub
parent 1217021a9a
commit 0334851cb1
3 changed files with 14 additions and 7 deletions

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
Fix "Cannot resolve from DOM point" error on onDomSelectionChange for readonly void elements

View File

@@ -31,7 +31,7 @@ import {
hasEditableTarget,
isEventHandled,
isDOMEventHandled,
isTargetInsideVoid,
isTargetInsideNonReadonlyVoid,
} from '../editable'
import { useAndroidInputManager } from './use-android-input-manager'
@@ -249,11 +249,11 @@ export const AndroidEditable = (props: EditableProps): JSX.Element => {
const anchorNodeSelectable =
hasEditableTarget(editor, anchorNode) ||
isTargetInsideVoid(editor, anchorNode)
isTargetInsideNonReadonlyVoid(editor, anchorNode)
const focusNodeSelectable =
hasEditableTarget(editor, focusNode) ||
isTargetInsideVoid(editor, focusNode)
isTargetInsideNonReadonlyVoid(editor, focusNode)
if (anchorNodeSelectable && focusNodeSelectable) {
const range = ReactEditor.toSlateRange(editor, domSelection, {

View File

@@ -289,11 +289,11 @@ export const Editable = (props: EditableProps) => {
const anchorNodeSelectable =
hasEditableTarget(editor, anchorNode) ||
isTargetInsideVoid(editor, anchorNode)
isTargetInsideNonReadonlyVoid(editor, anchorNode)
const focusNodeSelectable =
hasEditableTarget(editor, focusNode) ||
isTargetInsideVoid(editor, focusNode)
isTargetInsideNonReadonlyVoid(editor, focusNode)
if (anchorNodeSelectable && focusNodeSelectable) {
const range = ReactEditor.toSlateRange(editor, domSelection, {
@@ -1408,13 +1408,15 @@ export const hasEditableTarget = (
}
/**
* Check if the target is inside void and in the editor.
* Check if the target is inside void and in an non-readonly editor.
*/
export const isTargetInsideVoid = (
export const isTargetInsideNonReadonlyVoid = (
editor: ReactEditor,
target: EventTarget | null
): boolean => {
if (IS_READ_ONLY.get(editor)) return false
const slateNode =
hasTarget(editor, target) && ReactEditor.toSlateNode(editor, target)
return Editor.isVoid(editor, slateNode)