From 63e53f1bc91482a8230954336c36fe79cba06b8b Mon Sep 17 00:00:00 2001 From: Uri Gorelik Date: Fri, 15 Aug 2025 16:51:29 -0400 Subject: [PATCH] fix(tui): prevent dialog keymaps from being swallowed (#782) This change checks for the presence of a dialog before checking for other handlers. Now when pressing ctrl+p when a dialog is visible it will correctly navigate up the list. This restores the standard terminal behavior of using ctrl+n and ctrl+p. How to reproduce: 1. ctrl+p to open for the command launcher 2. ctrl+n (or down) to move down one item 3. ctrl+p - command dialog closed With this fix, step 3. will now correctly select the previous item in the dialog. --- internal/tui/tui.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/internal/tui/tui.go b/internal/tui/tui.go index 437b900da7f1665bc164e6b3db3e8a5581dd85d1..2f54e179b43bf288a1e7345ade3f5e68cfbfafe3 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -372,6 +372,11 @@ func (a *appModel) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd { return cmd } } + if a.dialog.HasDialogs() { + u, dialogCmd := a.dialog.Update(msg) + a.dialog = u.(dialogs.DialogCmp) + return dialogCmd + } switch { // help case key.Matches(msg, a.keyMap.Help): @@ -432,20 +437,14 @@ func (a *appModel) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd { } return tea.Suspend default: - if a.dialog.HasDialogs() { - u, dialogCmd := a.dialog.Update(msg) - a.dialog = u.(dialogs.DialogCmp) - return dialogCmd - } else { - item, ok := a.pages[a.currentPage] - if !ok { - return nil - } - - updated, cmd := item.Update(msg) - a.pages[a.currentPage] = updated.(util.Model) - return cmd + item, ok := a.pages[a.currentPage] + if !ok { + return nil } + + updated, cmd := item.Update(msg) + a.pages[a.currentPage] = updated.(util.Model) + return cmd } }