kommitters / editorjs-undo

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

Random bug when undoing #242

Open Jean-PhilippeD opened 10 months ago

Jean-PhilippeD commented 10 months ago

Precheck

Description

I use undo (and dragDrop which doesn't work by the way) and when I want to rollback some text with ctrl+Z sometimes it's working fine, sometimes it does erase whole blocks, append new empty block at the beginning, duplicates some other blocks...

I have no idea what's happening...

Environment

Current behavior

Here is the behavior :

bug-undo

I initialize editorJs like this :

editorRef.current = new EditorJS({
    holder: 'editorjs-container',
    autofocus: false,
    onReady: () => {
          const editor = editorRef.current;
          const undo = new Undo({ editor });
          undo.initialize(props.defaultValue);
    },
    tools: editorTools,
    data: props.defaultValue,
    readOnly: props.readOnly
});

Expected behavior

Undo to works fine :)

ARH3 commented 7 months ago

Hello I am having this same issue as well. It makes the plugin effectively unusable in practice. Would really appreciate if someone can work on this one. Thank you!!

juliandsg0222 commented 7 months ago

Hello @Jean-PhilippeD, thanks for reporting the issue, we were checking and now with version 2.0.27 it is not occurring, please try with the latest version and let us know if it works for you.

n2-freevas commented 7 months ago

Hello @juliandsg0222 . I have the same problem as @Jean-PhilippeD.

editorJS.current = new EditorJS({
        holder: "something",
        data: defaultBlock,
        ...
        onReady() {
          if (!!editorJS.current) {
            new Undo({
              editor: editorJS.current,
              maxLength: 20,
              config: {
                debounceTimer: 100,
                shortcuts: {
                  undo: 'CMD+Z',
                  redo: 'CMD+SHIFT+Z',
                },
              },
            });
            ...
          }
        },
     〜〜
     <div id="something"/>

**If Undo is performed immediately after the block data is mounted with the default value (defaultBlock), all block data will be lost. A subsequent Redo will restore the original data.

It seems to me that this could be avoided by determining if this is not the initial state before attempting to perform Undo, can this be fixed?**

juliandsg0222 commented 7 months ago

Hello @n2-freevas, thanks for the report, could you tell us which versions of editorjs and editorjs-undo you are using?

ARH3 commented 7 months ago

Hi @juliandsg0222 I continue to have the same issue on 2.0.27. Here is a loom video where I walk through the issue.

n2-freevas commented 6 months ago

@juliandsg0222 I've been using 2.0.27

keliumJU commented 6 months ago

Hello everyone 👋 @n2-freevas, @ARH3, @Jean-PhilippeD, We are currently working to fix these issues, at the moment to fix the problem of @ARH3 you can try preserving blank space in a paragraph, this problem had arisen a long time ago, you can check the discussion here https://github.com/codex-team/editor.js/discussions/1868#discussioncomment-1983196