mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-18 13:11: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:
5
.changeset/cyan-games-share.md
Normal file
5
.changeset/cyan-games-share.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix "Cannot resolve from DOM point" error on onDomSelectionChange for readonly void elements
|
@@ -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, {
|
||||||
|
@@ -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)
|
||||||
|
Reference in New Issue
Block a user