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

Fix error when trying to grab selection of a void node while read only (#3894)

* fix(react-editor): text node spacer can be non-existant if editor is in readonly mode

* v0.59.1

* Revert "v0.59.1"

This reverts commit 58cb7f1d61e81788e0257bace9be59bc47be8851.

* Update react-editor.ts

* Update react-editor.ts

* Create rude-lemons-crash.md

Co-authored-by: Ian Storm Taylor <ian@ianstormtaylor.com>
This commit is contained in:
Mikel Canovas 2021-03-31 15:33:28 -07:00 committed by GitHub
parent e344f47f03
commit 7fe41f1566
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -0,0 +1,5 @@
---
'slate-react': patch
---
Fixed an error that happened when selecting void nodes in a read-only editor.

View File

@ -478,14 +478,19 @@ export const ReactEditor = {
} else if (voidNode) {
// For void nodes, the element with the offset key will be a cousin, not an
// ancestor, so find it by going down from the nearest void parent.
leafNode = voidNode.querySelector('[data-slate-leaf]')!
textNode = leafNode.closest('[data-slate-node="text"]')!
domNode = leafNode
offset = domNode.textContent!.length
domNode.querySelectorAll('[data-slate-zero-width]').forEach(el => {
offset -= el.textContent!.length
})
// COMPAT: In read-only editors the leaf is not rendered.
if (!leafNode) {
offset = 1
} else {
textNode = leafNode.closest('[data-slate-node="text"]')!
domNode = leafNode
offset = domNode.textContent!.length
domNode.querySelectorAll('[data-slate-zero-width]').forEach(el => {
offset -= el.textContent!.length
})
}
}
// COMPAT: If the parent node is a Slate zero-width space, editor is