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:
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,
|
||||
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, {
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user