1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-24 09:13:24 +01:00

Fixing selection across a void node (i.e. mention or image) with the mouse (#3649)

* Fixing selection across a void node (i.e. mention or image) with the mouse.

* Fixing selection across a void nodes via mouse
This commit is contained in:
Nikolay Martynenko 2020-05-05 03:49:37 +03:00 committed by GitHub
parent d82ffe49a5
commit e25c30c7a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -364,11 +364,21 @@ export const Editable = (props: EditableProps) => {
IS_FOCUSED.delete(editor)
}
if (
domSelection &&
hasEditableTarget(editor, domSelection.anchorNode) &&
hasEditableTarget(editor, domSelection.focusNode)
) {
if (!domSelection) {
return Transforms.deselect(editor)
}
const { anchorNode, focusNode } = domSelection
const anchorNodeSelectable =
hasEditableTarget(editor, anchorNode) ||
isTargetInsideVoid(editor, anchorNode)
const focusNodeSelectable =
hasEditableTarget(editor, focusNode) ||
isTargetInsideVoid(editor, focusNode)
if (anchorNodeSelectable && focusNodeSelectable) {
const range = ReactEditor.toSlateRange(editor, domSelection)
Transforms.select(editor, range)
} else {
@ -977,6 +987,19 @@ const hasEditableTarget = (
)
}
/**
* Check if the target is inside void and in the editor.
*/
const isTargetInsideVoid = (
editor: ReactEditor,
target: EventTarget | null
): boolean => {
const slateNode =
hasTarget(editor, target) && ReactEditor.toSlateNode(editor, target)
return Editor.isVoid(editor, slateNode)
}
/**
* Check if an event is overrided by a handler.
*/