kommitters / editorjs-undo

Undo/Redo feature for Editor.js
https://www.npmjs.com/package/editorjs-undo
MIT License
169 stars 51 forks source link

Empty blocks are lost when performing an undo operation #53

Closed juanhurtado10 closed 3 years ago

juanhurtado10 commented 3 years ago

Context

https://user-images.githubusercontent.com/20125027/129673632-f1ec0d96-123f-46b2-b1b7-fc32fbe5089c.mov

komaldembla commented 3 years ago

Please find the list

Device, Browser, OS:

Editor.js version: 2.22.0

Plugins used with their versions:

MrJuanGaviriaK commented 3 years ago

Hi @komaldembla, @juanhurtado10

I've checked the issue and I noticed it is not related to the undo plugin.

Editor.js does not manage a line break as an empty block or an empty paragraph block then, the undo plugin just can't restore it because this is not even persisted into the history stack:

Screen Shot 2021-08-19 at 11 08 56 AM

There are workarounds to solve this:

But definitely, a root solution may be done on the editor.js core. Here are some references:

Best, Juan Gaviria

komaldembla commented 3 years ago

Thanks for the quick response here @MrJuanGaviriaK! I'll check the workarounds.

juanhurtado10 commented 3 years ago

@komaldembla @MrJuanGaviriaK

https://user-images.githubusercontent.com/1649973/132592356-07366fb1-227a-42b5-ad22-ae9e48517610.mov

After researching, I found that the following config allows the Undo plugin to recover the empty blocks.

  paragraph: {
    class: Paragraph,
    inlineToolbar: true,
    config: {
      preserveBlank: true,
    },
  },
  ...
komaldembla commented 3 years ago

@juanhurtado10 - Thank you so much! This works :)