From 03804cc476a14a713007563a48ab590f5c666a14 Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Thu, 18 Dec 2025 11:22:57 -0600 Subject: [PATCH] Fix undo/redo not firing when in a text box. --- inventory/static/js/components/draw.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/inventory/static/js/components/draw.js b/inventory/static/js/components/draw.js index 7ae6b8b..b968cc7 100644 --- a/inventory/static/js/components/draw.js +++ b/inventory/static/js/components/draw.js @@ -76,7 +76,14 @@ function initGridWidget(root, opts = {}) { const key = e.key.toLowerCase(); const t = e.target; - if (t && root.contains(t) && (t.matches('input, textarea, select') || t.isContentEditable)) return; + const isTextField = t && root.contains(t) && (t.matches('input, textarea, select') || t.isContentEditable); + + if (isTextField) { + const isUndo = (e.ctrlKey || e.metaKey) && key === 'z'; + const isRedo = (e.ctrlKey || e.metaKey) && (key === 'y' || (key === 'z' && e.shiftKey)); + + if (!isUndo && !isRedo) return; + } if ((e.ctrlKey || e.metaKey) && key === 'z') { e.preventDefault(); @@ -660,6 +667,11 @@ function initGridWidget(root, opts = {}) { }; saveDoc(doc); + + history.length = 0; + history.push(structuredClone(shapes)); + historyIndex = 0; + redrawAll(); } catch { toastMessage('Failed to load data from JSON file.', 'danger');