From eeecae023fefc7cd7d0451209b8c3efbbedd9cbd Mon Sep 17 00:00:00 2001 From: Dylan Markow Date: Fri, 6 Dec 2019 10:13:03 -0600 Subject: [PATCH] Force a zero offset when inside a void node (#3261) --- packages/slate-react/src/plugin/react-editor.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/slate-react/src/plugin/react-editor.ts b/packages/slate-react/src/plugin/react-editor.ts index a6cd697a7..b668d4209 100644 --- a/packages/slate-react/src/plugin/react-editor.ts +++ b/packages/slate-react/src/plugin/react-editor.ts @@ -197,6 +197,13 @@ export const ReactEditor = { const el = ReactEditor.toDOMNode(editor, node) let domPoint: DOMPoint | undefined + // If we're inside a void node, force the offset to 0, otherwise the zero + // width spacing character will result in an incorrect offset of 1 + const [match] = Editor.nodes(editor, { at: point, match: 'void' }) + if (match) { + point = { path: point.path, offset: 0 } + } + // For each leaf, we need to isolate its content, which means filtering // to its direct text and zero-width spans. (We have to filter out any // other siblings that may have been rendered alongside them.)