From 04db7c2f01355f2c43843794522380607e807716 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Mon, 23 Feb 2026 12:46:28 +0300 Subject: [PATCH] Enha: not allow popups outside of main page --- popups.go | 18 ++++++++++++++++++ tui.go | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/popups.go b/popups.go index 0226461..829a412 100644 --- a/popups.go +++ b/popups.go @@ -65,16 +65,19 @@ func showModelSelectionPopup() { chatBody.Model = modelName cfg.CurrentModel = chatBody.Model pages.RemovePage("modelSelectionPopup") + app.SetFocus(textArea) updateCachedModelColor() updateStatusLine() }) modelListWidget.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { if event.Key() == tcell.KeyEscape { pages.RemovePage("modelSelectionPopup") + app.SetFocus(textArea) return nil } if event.Key() == tcell.KeyRune && event.Rune() == 'x' { pages.RemovePage("modelSelectionPopup") + app.SetFocus(textArea) return nil } return event @@ -160,6 +163,7 @@ func showAPILinkSelectionPopup() { cfg.CurrentModel = chatBody.Model } pages.RemovePage("apiLinkSelectionPopup") + app.SetFocus(textArea) choseChunkParser() updateCachedModelColor() updateStatusLine() @@ -167,10 +171,12 @@ func showAPILinkSelectionPopup() { apiListWidget.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { if event.Key() == tcell.KeyEscape { pages.RemovePage("apiLinkSelectionPopup") + app.SetFocus(textArea) return nil } if event.Key() == tcell.KeyRune && event.Rune() == 'x' { pages.RemovePage("apiLinkSelectionPopup") + app.SetFocus(textArea) return nil } return event @@ -230,6 +236,7 @@ func showUserRoleSelectionPopup() { textView.SetText(chatToText(filtered, cfg.ShowSys)) // Remove the popup page pages.RemovePage("userRoleSelectionPopup") + app.SetFocus(textArea) // Update the status line to reflect the change updateStatusLine() colorText() @@ -237,10 +244,12 @@ func showUserRoleSelectionPopup() { roleListWidget.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { if event.Key() == tcell.KeyEscape { pages.RemovePage("userRoleSelectionPopup") + app.SetFocus(textArea) return nil } if event.Key() == tcell.KeyRune && event.Rune() == 'x' { pages.RemovePage("userRoleSelectionPopup") + app.SetFocus(textArea) return nil } return event @@ -303,16 +312,19 @@ func showBotRoleSelectionPopup() { cfg.WriteNextMsgAsCompletionAgent = mainText // Remove the popup page pages.RemovePage("botRoleSelectionPopup") + app.SetFocus(textArea) // Update the status line to reflect the change updateStatusLine() }) roleListWidget.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { if event.Key() == tcell.KeyEscape { pages.RemovePage("botRoleSelectionPopup") + app.SetFocus(textArea) return nil } if event.Key() == tcell.KeyRune && event.Rune() == 'x' { pages.RemovePage("botRoleSelectionPopup") + app.SetFocus(textArea) return nil } return event @@ -364,14 +376,17 @@ func showFileCompletionPopup(filter string) { textArea.SetText(before+mainText, true) } pages.RemovePage("fileCompletionPopup") + app.SetFocus(textArea) }) widget.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { if event.Key() == tcell.KeyEscape { pages.RemovePage("fileCompletionPopup") + app.SetFocus(textArea) return nil } if event.Key() == tcell.KeyRune && event.Rune() == 'x' { pages.RemovePage("fileCompletionPopup") + app.SetFocus(textArea) return nil } return event @@ -484,14 +499,17 @@ func showColorschemeSelectionPopup() { } // Remove the popup page pages.RemovePage("colorschemeSelectionPopup") + app.SetFocus(textArea) }) schemeListWidget.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { if event.Key() == tcell.KeyEscape { pages.RemovePage("colorschemeSelectionPopup") + app.SetFocus(textArea) return nil } if event.Key() == tcell.KeyRune && event.Rune() == 'x' { pages.RemovePage("colorschemeSelectionPopup") + app.SetFocus(textArea) return nil } return event diff --git a/tui.go b/tui.go index 638fdd6..0e95709 100644 --- a/tui.go +++ b/tui.go @@ -15,6 +15,11 @@ import ( "github.com/rivo/tview" ) +func isFullScreenPageActive() bool { + name, _ := pages.GetFrontPage() + return name != "main" +} + var ( app *tview.Application pages *tview.Pages @@ -525,6 +530,9 @@ func init() { return nil } if event.Key() == tcell.KeyRune && event.Rune() == 'i' && event.Modifiers()&tcell.ModAlt != 0 { + if isFullScreenPageActive() { + return event + } showColorschemeSelectionPopup() return nil } @@ -731,6 +739,9 @@ func init() { return nil } if event.Key() == tcell.KeyCtrlL { + if isFullScreenPageActive() { + return event + } // Show model selection popup instead of rotating models showModelSelectionPopup() return nil @@ -744,6 +755,9 @@ func init() { return nil } if event.Key() == tcell.KeyCtrlV { + if isFullScreenPageActive() { + return event + } // Show API link selection popup instead of rotating APIs showAPILinkSelectionPopup() return nil @@ -850,11 +864,17 @@ func init() { return nil } if event.Key() == tcell.KeyCtrlQ { + if isFullScreenPageActive() { + return event + } // Show user role selection popup instead of cycling through roles showUserRoleSelectionPopup() return nil } if event.Key() == tcell.KeyCtrlX { + if isFullScreenPageActive() { + return event + } // Show bot role selection popup instead of cycling through roles showBotRoleSelectionPopup() return nil