Fix undo/redo not firing when in a text box.

This commit is contained in:
Yaro Kasear 2025-12-18 11:22:57 -06:00
parent 65beb3509c
commit 03804cc476

View file

@ -76,7 +76,14 @@ function initGridWidget(root, opts = {}) {
const key = e.key.toLowerCase(); const key = e.key.toLowerCase();
const t = e.target; 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') { if ((e.ctrlKey || e.metaKey) && key === 'z') {
e.preventDefault(); e.preventDefault();
@ -660,6 +667,11 @@ function initGridWidget(root, opts = {}) {
}; };
saveDoc(doc); saveDoc(doc);
history.length = 0;
history.push(structuredClone(shapes));
historyIndex = 0;
redrawAll(); redrawAll();
} catch { } catch {
toastMessage('Failed to load data from JSON file.', 'danger'); toastMessage('Failed to load data from JSON file.', 'danger');