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.onChange
handler 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,
handlePasteEvent
is called in thePaste
component. - This in turn calls
processText
- Since multiple paragraphs are inserted, they are mapped to
insertBlock
calls- Each one calls
paste
in theBlockManager
-
paste
first callsinsert
on theBlockManager
a. At this point an empty block is created and inserted into DOM b.blockDidMutated
is triggered c. This in turn leads to theonChange
handler being called d. Since the block is still empty, the Paragraph tool returns nothing from itsdata
getter -
paste
then invokesblock.call(BlockToolAPI.ON_PASTE, pasteEvent)
a. This sets proper data on the newly inserted paragraph b.blockDidMutated
is not retriggered soonChange
signal 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?