Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toSlatePoint should not consider a selection within a void node if the void node isn't in the editor itself. #4885

Merged
merged 1 commit into from
Mar 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fuzzy-teachers-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'slate-react': patch
---

toSlatePoint should not consider a selection within a void node if the void node isn't in the editor itself.

Prior to this fix, a nested Slate editor inside a void node in a parent editor would not allow you to start typing text in a blank editor state correctly. After the first character insertion, the selection would jump back to the start of the nested editor.
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