mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-02-24 09:13:24 +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:
parent
e344f47f03
commit
7fe41f1566
5
.changeset/rude-lemons-crash.md
Normal file
5
.changeset/rude-lemons-crash.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixed an error that happened when selecting void nodes in a read-only editor.
|
@ -478,14 +478,19 @@ export const ReactEditor = {
|
|||||||
} else if (voidNode) {
|
} else if (voidNode) {
|
||||||
// For void nodes, the element with the offset key will be a cousin, not an
|
// 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.
|
// ancestor, so find it by going down from the nearest void parent.
|
||||||
|
|
||||||
leafNode = voidNode.querySelector('[data-slate-leaf]')!
|
leafNode = voidNode.querySelector('[data-slate-leaf]')!
|
||||||
textNode = leafNode.closest('[data-slate-node="text"]')!
|
|
||||||
domNode = leafNode
|
// COMPAT: In read-only editors the leaf is not rendered.
|
||||||
offset = domNode.textContent!.length
|
if (!leafNode) {
|
||||||
domNode.querySelectorAll('[data-slate-zero-width]').forEach(el => {
|
offset = 1
|
||||||
offset -= el.textContent!.length
|
} 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
|
// COMPAT: If the parent node is a Slate zero-width space, editor is
|
||||||
|
Loading…
x
Reference in New Issue
Block a user