@@ -305,9 +305,14 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
305305			}
306306		}
307307
308- 		// 8. Handle exit key debounce  for app exit when using  non-leader command  
308+ 		// 8. Handle immediate  exit command both  for empty and  non-empty editor  
309309		exitCommand  :=  a .app .Commands [commands .AppExitCommand ]
310- 		if  exitCommand .Matches (msg , a .app .IsLeaderSequence ) {
310+ 		if  exitCommand .Matches (msg , a .app .IsLeaderSequence ) &&  keyString  ==  "ctrl+d"  &&  a .editor .Length () ==  0  {
311+ 			return  a , util .CmdHandler (commands .ExecuteCommandMsg (exitCommand ))
312+ 		}
313+ 
314+ 		// 9. Handle exit key debounce for app exit when using non-leader command 
315+ 		if  exitCommand .Matches (msg , a .app .IsLeaderSequence ) &&  keyString  !=  "ctrl+d"  {
311316			switch  a .exitKeyState  {
312317			case  ExitKeyIdle :
313318				// First exit key press - start debounce timer 
@@ -324,22 +329,26 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
324329			}
325330		}
326331
327- 		// 9 . Check again for commands that don't require leader (excluding interrupt when busy and exit when in debounce) 
332+ 		// 10 . Check again for commands that don't require leader (excluding interrupt when busy and exit when in debounce) 
328333		matches  :=  a .app .Commands .Matches (msg , a .app .IsLeaderSequence )
329- 		if  len (matches ) >  0  {
334+ 		if  len (matches ) >  0  &&   keyString   !=   "ctrl+d"   {
330335			// Skip interrupt key if we're in debounce mode and app is busy 
331336			if  interruptCommand .Matches (msg , a .app .IsLeaderSequence ) &&  a .app .IsBusy () &&  a .interruptKeyState  !=  InterruptKeyIdle  {
332337				return  a , nil 
333338			}
339+ 			// Skip ctrl+d immediate exit key if the editor has content. Allow editor update commands to handle it as forward delete. 
340+ 			if  exitCommand .Matches (msg , a .app .IsLeaderSequence ) &&  keyString  ==  "ctrl+d"  &&  a .editor .Length () >  0  {
341+ 				return  a , nil 
342+ 			}
334343			return  a , util .CmdHandler (commands .ExecuteCommandsMsg (matches ))
335344		}
336345
337- 		// Fallback: suspend if ctrl+z is pressed and no user keybind matched 
346+ 		// 11.  Fallback: suspend if ctrl+z is pressed and no user keybind matched 
338347		if  keyString  ==  "ctrl+z"  {
339348			return  a , tea .Suspend 
340349		}
341350
342- 		// 10 . Fallback to editor. This is for other characters like backspace, tab, etc. 
351+ 		// 12 . Fallback to editor. This is for other characters like backspace, tab, etc. 
343352		updatedEditor , cmd  :=  a .editor .Update (msg )
344353		a .editor  =  updatedEditor .(chat.EditorComponent )
345354		return  a , cmd 
0 commit comments