penpa-edit icon indicating copy to clipboard operation
penpa-edit copied to clipboard

Pressing undo with main then secondary mouse buttons then releasing doesn't stop undoing

Open ghost opened this issue 3 years ago • 4 comments

Press the main mouse button on undo, then the secondary to get the menu, then release both. Undo will keep undoing. Not even pressing redo will cancel it and you have to refresh the whole page to remove the error

ghost avatar Aug 21 '20 21:08 ghost

This is seen at https://youtu.be/emH5qSvPTes?t=732 (12:12).

milliams avatar Aug 21 '20 22:08 milliams

I've been looking into this problem for some time now, but I couldn't figure out why. Now I've fixed the behavior involving the right click. Thank you for the comment. I have encountered this issue in other situations as well, so maybe the bug is still there. I will investigate.

opt-pan avatar Sep 03 '20 09:09 opt-pan

@opt-pan Here is one possible solution. Although this is not the perfect solution but seems to do better in improving the undo bug.

   function undoDown(e) {
        e.preventDefault();
        undo_button.classList.add('active');
        count_redo = 0;
        new_timer = setInterval(() => {
            count_undo++;
            if (count_undo > 5) {
                pu.undo();
            }
        }, 80);
        if (new_timer !== timer) {
            clearInterval(timer);
            count = 0;
        }
        timer = new_timer;
    }

    function undoUp(e) {
        e.preventDefault();
        undo_button.classList.remove('active');
        if (count_undo) {
            clearInterval(timer);
            count_undo = 0;
        }
    }

    function undoLeave(e) {
        e.preventDefault();
        undo_button.classList.remove('active');
        clearInterval(timer);
        count_undo = 0;
    }

    function redoDown(e) {
        e.preventDefault();
        redo_button.classList.add('active');
        count_undo = 0;
        new_timer = setInterval(() => {
            count_redo++;
            if (count_redo > 5) {
                pu.redo();
            }
        }, 80);
        if (new_timer !== timer) {
            clearInterval(timer);
            count = 0;
        }
        timer = new_timer;
    }

swaroopg92 avatar Sep 04 '20 04:09 swaroopg92

Thanks. The code is updated.

opt-pan avatar Sep 04 '20 22:09 opt-pan