Ctrl+Z to undo on empty editor crashes the editor
See original GitHub issueCreating an empty editor with html.deserialize('<p></p>')
, and then pressing Ctrl+Z
crashes the editor.
Instead initialize with a raw value:
Value.fromJSON({
document: {
nodes: [
{
kind: 'block',
type: 'paragraph',
nodes: [
{
kind: 'text',
leaves: [{ text: '' }]
}
]
}
]
}
})
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Editor crashes when executing Undo action after Audio ...
Editor crashes when executing Undo action after Audio Source component is added to Prefab ... Execute undo action (CTRL + Z)
Read more >Bug - Undo crashes Unity 2021.3.9+
Here's a repro case. Drag a prefab into the prefab field in the inspector, click "Add Prefab" and hit ctrl+z => Unity will...
Read more >Crash on undo (ctrl+z) in Filter Editor (#1688) · Issues · Inkscape ...
Steps to reproduce: open Inkscape; draw a shape; apply a filter on it, say 'Blur...' open 'filter editor'; Use slider to change standard...
Read more >[4.9.0] - Undo In Certain Case Causes Crash - C++
Without thinking, I accidently hit Ctrl+Z to undo and it caused an editor crash.
Read more >Undo crashes the Piskel editor - Bugs reports - GDevelop Forum
the error occurs not only for me alone. I am teaching one guy and he also wrote that the entire editor disappears when...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey @conorcussell thanks for the super clear writeup. I’d love a PR that fixes the
getSelectionIndexes
case.For the empty nodes case, Slate itself shouldn’t add a node, but I’d definitely be open to a PR that threw a more helpful error when that impossible case is run into. (Ideally in a single, or few places, wherever makes the most sense in that code path.)
Thank you!
I may just be repeating things people already know, but here are my findings from digging into this today.
When you create an empty editor the selection is unset, and an invalid selection is created because text is
undefined
.https://github.com/ianstormtaylor/slate/blob/199c32a2b5f776c586e7202cfa3183e551153fe4/packages/slate/src/models/value.js#L117-L120
This also happens with copy and paste because the onPaste plugin invokes
Plain.deserialize
which in turn invokesValue.fromJSON
In the render method of slate-react’s content component
getSelectionIndexes
is called with astartKey
andendKey
of null, which callsgetFurthestAncestor
withnull
and gives us the error.https://github.com/ianstormtaylor/slate/blob/199c32a2b5f776c586e7202cfa3183e551153fe4/packages/slate/src/models/node.js#L1410-L1414
Simply returning
null
ingetSelectionIndexes
whenstartKey
andendKey
are null will fix this case, and copy + pasting but it will not fix the case mentioned in https://github.com/ianstormtaylor/slate/issues/1161. If the editor won’t work without any nodes in it, should we ensure there is at least one node by default?