opt-pan / penpa-edit

MIT License
29 stars 22 forks source link

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

Open ghost opened 4 years ago

ghost commented 4 years ago

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

milliams commented 4 years ago

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

opt-pan commented 4 years ago

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.

swaroopg92 commented 4 years ago

@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;
    }
opt-pan commented 4 years ago

Thanks. The code is updated.