fix: undo no longer swallowed when focus is in the task input

Cmd/Ctrl+Z did nothing in normal use. The handler bailed out whenever the
event target was an input, which was meant to protect the field's own text
undo. But the add-task input is where focus usually sits: you click it to
add a task and stay there, and on macOS clicking a button doesn't move
focus. So the guard killed undo in the one situation it exists for, right
after deleting something.

It now defers to the field only when the field actually holds text. An
empty input has nothing to restore.

The decision moves to src/lib/shortcuts.js as a pure function, because the
inline version couldn't be tested. Shift+Cmd+Z means redo and no longer
triggers an undo.
This commit is contained in:
Aculix Technologies
2026-08-16 01:20:55 +05:30
parent b837ecd67f
commit 143fcc205d
3 changed files with 112 additions and 3 deletions
+2 -3
View File
@@ -9,6 +9,7 @@
import { rollover, msUntilNextMidnight } from './lib/rollover.js';
import * as taskOps from './lib/tasks.js';
import { createUndoStack, applyUndo } from './lib/undo.js';
import { shouldHandleUndo } from './lib/shortcuts.js';
const storage = createStorage();
const undoStack = createUndoStack();
@@ -88,9 +89,7 @@
}
function handleGlobalKeydown(event) {
if (!(event.metaKey || event.ctrlKey) || event.key.toLowerCase() !== 'z') return;
// Leave the text field its own native undo.
if (event.target instanceof HTMLInputElement) return;
if (!shouldHandleUndo(event)) return;
event.preventDefault();
undo();
}