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

[Bug] Deleting multiple selected blocks sends onChange event for only one block

Open jggc opened this issue 4 years ago • 3 comments

Steps to reproduce:

  1. Write multiple blocks
  2. Select them
  3. Delete them
  4. only one onChange event is sent for one of the blocks, nothing for the other blocks

Expected behavior: Receive one onChange per block or a list of affected blocks in the change

jggc avatar May 31 '21 16:05 jggc

The bug is worse than expected : only one of the blocks is actually deleted in the editor's internal structure.

If we call editor.save() the other deleted blocks are still returned, only one of them is actually deleted.

jggc avatar Jun 02 '21 13:06 jggc

I was able to overcome this issue using the onChange callback by calling the api.saver.save() with a small delay. 🤷‍♂️ https://editorjs.io/configuration#editor-modifications-callback https://editorjs.io/saver#save

This approach also helped me to fix related issue when editor doesn't save pasted multi-line text https://github.com/codex-team/editor.js/issues/1755.

const handleChange = (api /*, block */) => {
  setTimeout(() => {
    api.saver.save().then(
      (editorData) => console.log(JSON.stringify(editorData))
    );
  }, 200);    
};

const editor = new EditorJS({
  ... // pass configuration props
  onChange: handleChange, 
});

vasiliy-l avatar Sep 28 '21 19:09 vasiliy-l

Are there any updates on this? The above mentioned approach is only a workaround and doesn't work in all cases. For example if text is inserted programmatically into the editor. The editor itself is recognizing the change (at least the "Editor.js saving" is logged in the console), but no onChange is called at all. So delaying the save doesn't work in this case.

psalchow avatar Mar 31 '22 06:03 psalchow