1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-18 21:21:21 +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, hasEditableTarget,
isEventHandled, isEventHandled,
isDOMEventHandled, isDOMEventHandled,
isTargetInsideVoid, isTargetInsideNonReadonlyVoid,
} from '../editable' } from '../editable'
import { useAndroidInputManager } from './use-android-input-manager' import { useAndroidInputManager } from './use-android-input-manager'
@@ -249,11 +249,11 @@ export const AndroidEditable = (props: EditableProps): JSX.Element => {
const anchorNodeSelectable = const anchorNodeSelectable =
hasEditableTarget(editor, anchorNode) || hasEditableTarget(editor, anchorNode) ||
isTargetInsideVoid(editor, anchorNode) isTargetInsideNonReadonlyVoid(editor, anchorNode)
const focusNodeSelectable = const focusNodeSelectable =
hasEditableTarget(editor, focusNode) || hasEditableTarget(editor, focusNode) ||
isTargetInsideVoid(editor, focusNode) isTargetInsideNonReadonlyVoid(editor, focusNode)
if (anchorNodeSelectable && focusNodeSelectable) { if (anchorNodeSelectable && focusNodeSelectable) {
const range = ReactEditor.toSlateRange(editor, domSelection, { const range = ReactEditor.toSlateRange(editor, domSelection, {

View File

@@ -289,11 +289,11 @@ export const Editable = (props: EditableProps) => {
const anchorNodeSelectable = const anchorNodeSelectable =
hasEditableTarget(editor, anchorNode) || hasEditableTarget(editor, anchorNode) ||
isTargetInsideVoid(editor, anchorNode) isTargetInsideNonReadonlyVoid(editor, anchorNode)
const focusNodeSelectable = const focusNodeSelectable =
hasEditableTarget(editor, focusNode) || hasEditableTarget(editor, focusNode) ||
isTargetInsideVoid(editor, focusNode) isTargetInsideNonReadonlyVoid(editor, focusNode)
if (anchorNodeSelectable && focusNodeSelectable) { if (anchorNodeSelectable && focusNodeSelectable) {
const range = ReactEditor.toSlateRange(editor, domSelection, { 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, editor: ReactEditor,
target: EventTarget | null target: EventTarget | null
): boolean => { ): boolean => {
if (IS_READ_ONLY.get(editor)) return false
const slateNode = const slateNode =
hasTarget(editor, target) && ReactEditor.toSlateNode(editor, target) hasTarget(editor, target) && ReactEditor.toSlateNode(editor, target)
return Editor.isVoid(editor, slateNode) return Editor.isVoid(editor, slateNode)