From 9f33d1c4b28373fbf00a17c2bd46102623ff4fc5 Mon Sep 17 00:00:00 2001 From: Dominik Date: Thu, 11 Dec 2025 15:01:51 +0100 Subject: [PATCH] Browsing through a menu now does not change where the selection was in the previous menu when returning --- src/tui.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tui.go b/src/tui.go index 49288d2..e29b636 100644 --- a/src/tui.go +++ b/src/tui.go @@ -3,9 +3,6 @@ package main import ( "fmt" "os" - //"sort" - //"strings" - "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/list" @@ -30,6 +27,7 @@ type model struct { currentView view currentKey string selectedCmd string + categoryIndex int } func (m model) Init() tea.Cmd { return nil } @@ -48,10 +46,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { selected, ok := m.list.SelectedItem().(item) if ok { if m.currentView == viewCategories { + m.categoryIndex = m.list.Index() m.currentKey = selected.title m.currentView = viewCommands m.list.Title = m.currentKey m.list.SetItems(cmdItemsToList(m.commands.Get(m.currentKey))) + m.list.Select(0) } else if m.currentView == viewCommands { m.selectedCmd = selected.title return m, tea.Quit @@ -64,6 +64,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.currentView = viewCategories m.list.Title = "Choose a list of commands" m.list.SetItems(cmdListKeysToList(m.commands)) + m.list.Select(m.categoryIndex) } }