Open jrs64 opened 1 year ago
I would like to take this up.
@jrs64 what behaviour do we want to achieve over here? do you want the read only component deleted in this case or it should be untouched?
@jrs64 what behaviour do we want to achieve over here? do you want the read only component deleted in this case or it should be untouched?
The ideal behavior would be to delete the element, or at least ensure that the page does not crash
@jrs64 got it thanks I'll work on this and will let you know.
I stumbled over the same error. in my scenario I have a readonly element that sits on top of every editor element and user can click on but its not part of the text.
it can happen that user selects text backwards to the beginning of the element and happens to accidentally move mouse a bit up at the beginning of element and then hits delete and gets a crash.
so I would like the editor to ignore selection of the contentEditable={false}
element.
for the time being, I'll try "fixing" the bad selection of the user by hooking set_selection
op and verifying there are no readOnly elements in the selection.
@jrs64 I seem to have been able to fix this easily by adding data-slate-void
to the readOnly element.
I guess at best one would want to properly define all the void elements and handle their rendering individually so that attribute gets added automatically. (see https://docs.slatejs.org/api/nodes/editor#schema-specific-instance-methods-to-override and https://docs.slatejs.org/api/nodes/element#rendering-void-elements
however in cases where you want to render a void as part of an editable element, it seems to work fine adding that attribute manually.
Hey I'm unable to work on this issue, if anyone interested can please take this up.
Hey, adding data-slate-void
manually didn't work for me. Are there any more workarounds for this issue?
@ScottHowieOptimove hm. still works for me on "slate-react": "^0.101.0"
. just to be more clear what I did:
const renderElement = ({ attributes, children, element }: RenderElementProps): React.ReactElement => {
switch (element.type) {
...
return (
<Container {...attributes}>
{/* mark manually as void-element to make it behave properly, eg non-selectable */}
<Box contentEditable={false} data-slate-void>
// here are my elements that are not editable but caused crash when part of selection + delete
</Box>
{children}
</Container>
)
}
@philicious thanks for the reply. Maybe it's because I'm using an older version of slate. Will try updating. Thanks again!
Description When you select some text and readOnly element, then press the
delete
key, Slate crashes and displays the following error message:Recording
https://github.com/ianstormtaylor/slate/assets/44115045/9de2eb7c-083f-44f0-8808-bf35d73bf501
Sandbox https://www.slatejs.org/examples/inlines
Steps To reproduce the behavior:
Expectation Slate should not crash, and delete selector text
Environment