editor.js
editor.js copied to clipboard
[Bug] Order of events is wrong for paste
onChange event is fired before pasted content becomes visible through editor.save().
Steps to reproduce:
- Create an
editor.onChangehandler that prints the results ofawait editor.save() - Paste multiple paragraphs into the editor
- Notice how the last paragraph is missing from the saved state
Expected behavior:
All paragraphs are present.
Screenshots:
N/A
Device, Browser, OS:
N/A
Editor.js version:
next from GitHub but the bug is also present in the current live demo page
Plugins you use with their versions:
Default plugins from example-dev.html
Here's what's happening:
- When content is pasted,
handlePasteEventis called in thePastecomponent. - This in turn calls
processText - Since multiple paragraphs are inserted, they are mapped to
insertBlockcalls- Each one calls
pastein theBlockManager pastefirst callsinserton theBlockManagera. At this point an empty block is created and inserted into DOM b.blockDidMutatedis triggered c. This in turn leads to theonChangehandler being called d. Since the block is still empty, the Paragraph tool returns nothing from itsdatagetterpastethen invokesblock.call(BlockToolAPI.ON_PASTE, pasteEvent)a. This sets proper data on the newly inserted paragraph b.blockDidMutatedis not retriggered soonChangesignal is not invoked
- Each one calls
I think it would be cleaner if tool's onPaste was called before calling BlockManager.insert and if it returned the initial data to pass to BlockManager.insert.
Seconded, we have this issue as well. It makes it very easy for the user to lose pasted information.
Any updates on this bug? I have also experienced this inconsistent saving behavior when pasting data into the Editor.

Also struggling with this issue and am hoping for solution. +1
+1
+1
Still bugged more than a year after opening.. has the EditorJ project been abandoned?