editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

[Bug] Order of events is wrong for paste

Open patrys opened this issue 2 years ago • 3 comments

onChange event is fired before pasted content becomes visible through editor.save().

Steps to reproduce:

  1. Create an editor.onChange handler that prints the results of await editor.save()
  2. Paste multiple paragraphs into the editor
  3. 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:

  1. When content is pasted, handlePasteEvent is called in the Paste component.
  2. This in turn calls processText
  3. Since multiple paragraphs are inserted, they are mapped to insertBlock calls
    1. Each one calls paste in the BlockManager
    2. paste first calls insert on the BlockManager a. At this point an empty block is created and inserted into DOM b. blockDidMutated is triggered c. This in turn leads to the onChange handler being called d. Since the block is still empty, the Paragraph tool returns nothing from its data getter
    3. paste then invokes block.call(BlockToolAPI.ON_PASTE, pasteEvent) a. This sets proper data on the newly inserted paragraph b. blockDidMutated is not retriggered so onChange signal is not invoked

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.

patrys avatar May 17 '22 19:05 patrys

Seconded, we have this issue as well. It makes it very easy for the user to lose pasted information.

markedwards avatar May 26 '22 08:05 markedwards

Any updates on this bug? I have also experienced this inconsistent saving behavior when pasting data into the Editor.

Jun-14-2022 16-36-05

borisevstratov avatar Jun 14 '22 13:06 borisevstratov

Also struggling with this issue and am hoping for solution. +1

danlynkew avatar Jun 17 '22 20:06 danlynkew

+1

Exifers avatar Oct 06 '22 13:10 Exifers

+1

daniel-kargari avatar Dec 19 '22 08:12 daniel-kargari

Still bugged more than a year after opening.. has the EditorJ project been abandoned?

ale-stor avatar Sep 02 '23 19:09 ale-stor