editor.js
editor.js copied to clipboard
Entering text into empty first block on new document triggers 'block-changed' event rather than 'block-created'
If a new editor is instantiated and no initial data is provided, editorjs creates an empty block in which the cursor is set. If the user starts typing in this block, editorjs triggers the event block-changed.
Steps to reproduce:
- Initialise an empty editorjs instance
- Provide an
onChangefunction and listen to it - Start typing in the first empty block
- Check the console
Here's a demo implementation: https://6246d3405682fb7683a8b9be--editorjs-bug.netlify.app
Expected behavior:
Editors should trigger the event block-created because before the first input no block exists that could be updated.
Device, Browser, OS: Safari and Chrome on Mac OS
Editor.js version: 2.23.2
The editor always has at least one Block. So the empty editor has the only block. And when you started typing, it is actually changed, not created.
Maybe we should consider triggering the block-created on the empty editor initialization. What do you think?
I have the same issue with the latest version.
The editor always has at least one Block. So the empty editor has the only block. And when you started typing, it is actually changed, not created.
If you try to save the empty editor, you'll get an empty list of block. The only way I found to get the first block was to use Editor.blocks.getBlockByIndex(0), which returns the first block.
Maybe we should consider triggering the
block-createdon the empty editor initialization. What do you think?
That's the behavior I was expecting from editor.js but I don't know well enough the lib to say that triggering the block-created event is the way to go. Adding a note in the documentation about this behavior could be enough. The workaround is quite simple, using getBlockByIndex(0) in onReady gives the first block.
Actually, clearing the editor does trigger the event block-created. It can be used to work around this issue.