@@ -16,7 +16,7 @@ import { useHandleNewThread } from "../hooks/useHandleNewThread";
1616import { startNewThreadFromContext } from "../lib/chatThreadActions" ;
1717import { isPreviewFocused } from "../lib/previewFocus" ;
1818import { isTerminalFocused } from "../lib/terminalFocus" ;
19- import { isEditableFocused } from "../lib/editableFocus" ;
19+ import { editableOwnsUndo , isEditableFocused } from "../lib/editableFocus" ;
2020import { isModelPickerOpen } from "../modelPickerVisibility" ;
2121import { undoLatestThreadAction } from "../hooks/showThreadUndoNotice" ;
2222import { resolveShortcutCommand } from "../keybindings" ;
@@ -60,6 +60,32 @@ function ChatRouteGlobalShortcuts() {
6060 ? selectActiveRightPanel ( state . byThreadKey , routeThreadRef ) === "preview"
6161 : false ,
6262 ) ;
63+ // Capture phase: the composer's editor claims mod+z (and marks it handled)
64+ // even when it is empty, which would otherwise starve the thread Undo notice.
65+ useEffect ( ( ) => {
66+ const onUndoKeyDown = ( event : KeyboardEvent ) => {
67+ const command = resolveShortcutCommand ( event , keybindings , {
68+ context : {
69+ terminalFocus : isTerminalFocused ( ) ,
70+ terminalOpen,
71+ previewFocus : isPreviewFocused ( ) ,
72+ previewOpen,
73+ editableFocus : editableOwnsUndo ( event . target ) ,
74+ modelPickerOpen : isModelPickerOpen ( ) ,
75+ } ,
76+ } ) ;
77+ if ( command !== "thread.undo" ) return ;
78+ if ( event . repeat || isCommandPaletteOpen ( ) || isModelPickerOpen ( ) ) return ;
79+ if ( undoLatestThreadAction ( ) ) {
80+ event . preventDefault ( ) ;
81+ event . stopPropagation ( ) ;
82+ }
83+ } ;
84+
85+ window . addEventListener ( "keydown" , onUndoKeyDown , true ) ;
86+ return ( ) => window . removeEventListener ( "keydown" , onUndoKeyDown , true ) ;
87+ } , [ keybindings , previewOpen , terminalOpen ] ) ;
88+
6389 useEffect ( ( ) => {
6490 const onWindowKeyDown = ( event : KeyboardEvent ) => {
6591 if ( event . defaultPrevented ) return ;
@@ -78,15 +104,6 @@ function ChatRouteGlobalShortcuts() {
78104 return ;
79105 }
80106
81- if ( command === "thread.undo" ) {
82- if ( event . repeat || isModelPickerOpen ( ) ) return ;
83- if ( undoLatestThreadAction ( ) ) {
84- event . preventDefault ( ) ;
85- event . stopPropagation ( ) ;
86- }
87- return ;
88- }
89-
90107 if ( event . key === "Escape" && selectedThreadKeysSize > 0 ) {
91108 event . preventDefault ( ) ;
92109 clearSelection ( ) ;
0 commit comments