From 08f195eb12d91286f99dfab6a7643aa507e686d4 Mon Sep 17 00:00:00 2001 From: Hans5958 Date: Fri, 6 May 2022 14:26:29 +0700 Subject: [PATCH] Use mouse position when undo/redo/reset --- web/_js/draw.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/web/_js/draw.js b/web/_js/draw.js index f9c5cf18..76fc1a7b 100644 --- a/web/_js/draw.js +++ b/web/_js/draw.js @@ -169,7 +169,7 @@ function initDraw() { if (!dragging && drawing && path.length > 0) { const coords = getCanvasCoords(e.clientX, e.clientY); - render(path.concat([coords])); + render([...path, coords]); } }); @@ -204,16 +204,22 @@ function initDraw() { finish(); }); - undoButton.addEventListener("click", function() { + undoButton.addEventListener("click", function(e) { undo(); + const coords = getCanvasCoords(e.clientX, e.clientY); + render([...path, coords]); }); - redoButton.addEventListener("click", function() { + redoButton.addEventListener("click", function(e) { redo(); + const coords = getCanvasCoords(e.clientX, e.clientY); + render([...path, coords]); }); - resetButton.addEventListener("click", function() { + resetButton.addEventListener("click", function(e) { reset(); + const coords = getCanvasCoords(e.clientX, e.clientY); + render([...path, coords]); }); resetButton.addEventListener("blur", function() {