Open silviubogan opened 4 years ago
Transforms.removeNodes(editor, { at: [0, 0]})
@LeonAlvarez Thank you for your answer. Do you have any idea how can I remove nodes that are not leaf (Text) nodes? At [0] I have a numbered list, I want to delete it entirely. I think that this would be a useful walk-around for me to the issue.
I'm a little surprised normalisation doesn't adjust the empty document, but I guess it can't know how your elements are structured. Anyway, there are a couple of ways to fix this. Note that text nodes must have blocks around them, so both of these require changing the insert to { children: [{text: 'a'}] }
[0]
, remove at [1]
[0]
first, but insert with no at
set e.g. just Transforms.insertNodes( editor, { children: [{text: 'a'}] } )
Do you want to request a feature or report a bug?
Bug.
What's the current behavior?
Transforms.insertNodes(editor, { text: 'a' }, { at: Editor.start(editor, [0]) });
fails because there is no node at[0]
to insert at, andEditor.start(editor, [])
throws an error because[]
is the root path at which there is noText
node, but the editor. So I cannot insert something at the beginning of the editor.So the relevant code from the sandbox is inside the click handler of the button:
I am not sure which case should work but I think that both would be great to work.
The sandbox: https://codesandbox.io/s/slate-reproductions-zkghr?file=/index.js (in the sandbox, just click the button, watch the error console, then switch the comments so that
case 1
is executed and notcase 2
and then click the button again).Slate: 0.58.3 Browser: Chrome, Firefox (although I think it is a cross-browser issue) OS: Linux (Ubuntu 20.04)
What's the expected behavior?
No errors in the console. Text is inserted at the beginning of the editor which should be empty before the
insertNodes
call.Thank you.