Skip to content

Commit 3f6c6c4

Browse files
committed
fix(web): a modifier tapped mid-hold keeps mod+z repeats cancelled
The held undo key was forgotten on any fresh keydown, so tapping Shift while holding mod+z let later repeats reach the editor's own undo. It is now remembered by key code and only a fresh non-modifier press clears it.
1 parent 90e298f commit 3f6c6c4

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎apps/web/src/components/AppSidebarLayout.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,19 @@ function ThreadUndoShortcut() {
236236
const noticeVisible = useSidebarVisibility();
237237

238238
useEffect(() => {
239-
let undoKeyHeld = false;
239+
let heldUndoKey: string | null = null;
240240
const onKeyDown = (event: KeyboardEvent) => {
241241
// A held key undoes once. Cancel its repeats so they cannot fall through
242242
// to the editor's own undo, even after the last notice is gone.
243243
if (event.repeat) {
244-
if (undoKeyHeld) {
244+
if (event.code === heldUndoKey) {
245245
event.preventDefault();
246246
event.stopPropagation();
247247
}
248248
return;
249249
}
250-
undoKeyHeld = false;
250+
// A modifier tapped mid-hold leaves the held key repeating.
251+
if (!MODIFIER_KEYS.has(event.key)) heldUndoKey = null;
251252
const command = resolveShortcutCommand(event, keybindings, {
252253
context: {
253254
terminalFocus: isTerminalFocused(),
@@ -263,7 +264,7 @@ function ThreadUndoShortcut() {
263264
}
264265
if (isCommandPaletteOpen() || isModelPickerOpen()) return;
265266
if (undoLatestThreadAction()) {
266-
undoKeyHeld = true;
267+
heldUndoKey = event.code;
267268
event.preventDefault();
268269
event.stopPropagation();
269270
}

0 commit comments

Comments
 (0)