kommitters / editorjs-undo

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

undo functionality doesn't work when splitting text by pressing enter #243

Closed abdallahalsamman closed 3 months ago

abdallahalsamman commented 3 months ago

Precheck

Description

if I put the cursor in the middle of paragraph text and hit enter, I will have a new paragraph with the right part of text.

Now if I hit ctrl + z, nothing happens.

Environment

Current behavior

Nothing happens on ctrl + z

Expected behavior

Undo show remove the new paragraph and put the text how it was

Additional context

Add any other context about the problem here.

MarioRodriguezS commented 3 months ago

@abdallahalsamman Thank you for reporting the issue! We've been trying to reproduce it without success. Could you please provide more context or a video? Additionally, if there are any console messages associated with the issue, they would be helpful. I've attached a video showing our attempt.

https://github.com/kommitters/editorjs-undo/assets/64106728/dfe376ac-3bb3-4130-a54c-e5f8f02fd027

MarioRodriguezS commented 3 months ago

@abdallahalsamman While attempting to reproduce the reported issue, we found a related issue related to the redo action, which has already been worked on pull request #244. However, we have not yet been able to reproduce your reported issue.

abdallahalsamman commented 3 months ago

I will update the package and test to see if the issue is still happening

abdallahalsamman commented 3 months ago

@MarioRodriguezS it's still happening here even after I upgrade to 2.0.26

Screencast from 26-03-24 23:20:27.webm

I pressed contrl z so many times

function initEditor(editorjs_div) {
    const initialData = JSON.parse(editorjs_div.dataset.editorjsData);
    const editor = new EditorJS({
        holder: 'editorjs',
        data: initialData,
        tools: {
            header: {
                class: Header,
                inlineToolbar: true
            },
            list: {
                class: List,
                inlineToolbar: true
            },
            table: Table,
            assistant: {
                class: Assistant,
                config: {
                    assistantUrl: editorjs_div.dataset.assistantUrl,
                    csrfToken: document.querySelector('input[name="_token"]').value
                },
                shortcut: 'CTRL+M'
            }
        },
        onReady: () => {
            const undo = new Undo({
                editor,
                config: {
                    shortcuts: {
                        undo: 'CTRL+Z',
                        redo: 'CTRL+SHIFT+Z'
                    }
                }
            });
            undo.initialize(initialData);
        },
        onChange: _.debounce(() => mySaveFunction(editor, editorjs_div), 200)
    });
}
miguelnietoa commented 3 months ago

@abdallahalsamman The plugin expects CMD rather than CTRL. CMD will be set up automatically as Ctrl or ⌘ depending on the client OS. Try updating the shortcuts:

shortcuts: {
    undo: 'CMD+Z',
    redo: 'CMD+SHIFT+Z'
}
MarioRodriguezS commented 3 months ago

@abdallahalsamman Indeed, there is a bug when performing the action you mentioned. Once you have properly set up the plugin, you will encounter it. We will be working on fixing it as soon as possible.

MarioRodriguezS commented 3 months ago

@abdallahalsamman Thanks again for reporting the issue, it was solved and the solution is available in v2.0.27. Let us know if it is helpful to you.

Cheers.