fix: ensure it's possible to quit (`ctrl+c`) even when a dialog is open (#1007)

Andrey Nering created

Change summary

internal/tui/tui.go | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)

Detailed changes

internal/tui/tui.go 🔗

@@ -406,6 +406,16 @@ func (a *appModel) handleWindowResize(width, height int) tea.Cmd {
 
 // handleKeyPressMsg processes keyboard input and routes to appropriate handlers.
 func (a *appModel) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
+	// Check this first as the user should be able to quit no matter what.
+	if key.Matches(msg, a.keyMap.Quit) {
+		if a.dialog.ActiveDialogID() == quit.QuitDialogID {
+			return tea.Quit
+		}
+		return util.CmdHandler(dialogs.OpenDialogMsg{
+			Model: quit.NewQuitDialog(),
+		})
+	}
+
 	if a.completions.Open() {
 		// completions
 		keyMap := a.completions.KeyMap()
@@ -430,14 +440,6 @@ func (a *appModel) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
 		a.showingFullHelp = !a.showingFullHelp
 		return a.handleWindowResize(a.wWidth, a.wHeight)
 	// dialogs
-	case key.Matches(msg, a.keyMap.Quit):
-		if a.dialog.ActiveDialogID() == quit.QuitDialogID {
-			return tea.Quit
-		}
-		return util.CmdHandler(dialogs.OpenDialogMsg{
-			Model: quit.NewQuitDialog(),
-		})
-
 	case key.Matches(msg, a.keyMap.Commands):
 		// if the app is not configured show no commands
 		if !a.isConfigured {