Skip to content

Commit

Permalink
When resolving a slate Point from a DOM selection (toSlatePoint), con…
Browse files Browse the repository at this point in the history
…sider that a node is only void if it's within the same editor that is resolving the Point.

If you have a nested editor setup. For example, one editor has a void node that contains another editor. In this case, a resolution of a selection by the nested editor previously would consider that the selection is for a void node since an ancestor void node does exist. However, this selection is only a void node in the context of this editor if the ancestor void node is contained in the editor.
  • Loading branch information
ryanmitts committed Mar 12, 2022
1 parent 2a620dc commit 39f19ec
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/slate-react/src/plugin/react-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,16 @@ export const ReactEditor = {
let offset = 0

if (parentNode) {
const voidNode = parentNode.closest('[data-slate-void="true"]')
const editorEl = ReactEditor.toDOMNode(editor, editor)
const potentialVoidNode = parentNode.closest('[data-slate-void="true"]')
// Need to ensure that the closest void node is actually a void node
// within this editor, and not a void node within some parent editor. This can happen
// if this editor is within a void node of another editor ("nested editors", like in
// the "Editable Voids" example on the docs site).
const voidNode =
potentialVoidNode && editorEl.contains(potentialVoidNode)
? potentialVoidNode
: null
let leafNode = parentNode.closest('[data-slate-leaf]')
let domNode: DOMElement | null = null

Expand Down

0 comments on commit 39f19ec

Please sign in to comment.