From 31709160a32b18c2af53062a911bede3bb8fdfbe Mon Sep 17 00:00:00 2001 From: Nikolay Martynenko Date: Thu, 21 May 2020 03:26:21 +0300 Subject: [PATCH] Fix selection, if click event fired after (#3650) --- packages/slate-react/src/components/editable.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index 054b96291..8c7260f35 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -7,6 +7,7 @@ import { Range, Text, Transforms, + Path, } from 'slate' import throttle from 'lodash/throttle' import scrollIntoView from 'scroll-into-view-if-needed' @@ -554,8 +555,16 @@ export const Editable = (props: EditableProps) => { const node = ReactEditor.toSlateNode(editor, event.target) const path = ReactEditor.findPath(editor, node) const start = Editor.start(editor, path) + const end = Editor.end(editor, path) - if (Editor.void(editor, { at: start })) { + const startVoid = Editor.void(editor, { at: start }) + const endVoid = Editor.void(editor, { at: end }) + + if ( + startVoid && + endVoid && + Path.equals(startVoid[1], endVoid[1]) + ) { const range = Editor.range(editor, start) Transforms.select(editor, range) }