mirror of
https://github.com/agresdominik/cheat_sheet.git
synced 2026-04-21 18:05:51 +00:00
Browsing through a menu now does not change where the selection was in the previous menu when returning
This commit is contained in:
+4
-3
@@ -3,9 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
//"sort"
|
|
||||||
//"strings"
|
|
||||||
|
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/key"
|
"github.com/charmbracelet/bubbles/key"
|
||||||
"github.com/charmbracelet/bubbles/list"
|
"github.com/charmbracelet/bubbles/list"
|
||||||
@@ -30,6 +27,7 @@ type model struct {
|
|||||||
currentView view
|
currentView view
|
||||||
currentKey string
|
currentKey string
|
||||||
selectedCmd string
|
selectedCmd string
|
||||||
|
categoryIndex int
|
||||||
}
|
}
|
||||||
func (m model) Init() tea.Cmd { return nil }
|
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)
|
selected, ok := m.list.SelectedItem().(item)
|
||||||
if ok {
|
if ok {
|
||||||
if m.currentView == viewCategories {
|
if m.currentView == viewCategories {
|
||||||
|
m.categoryIndex = m.list.Index()
|
||||||
m.currentKey = selected.title
|
m.currentKey = selected.title
|
||||||
m.currentView = viewCommands
|
m.currentView = viewCommands
|
||||||
m.list.Title = m.currentKey
|
m.list.Title = m.currentKey
|
||||||
m.list.SetItems(cmdItemsToList(m.commands.Get(m.currentKey)))
|
m.list.SetItems(cmdItemsToList(m.commands.Get(m.currentKey)))
|
||||||
|
m.list.Select(0)
|
||||||
} else if m.currentView == viewCommands {
|
} else if m.currentView == viewCommands {
|
||||||
m.selectedCmd = selected.title
|
m.selectedCmd = selected.title
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
@@ -64,6 +64,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.currentView = viewCategories
|
m.currentView = viewCategories
|
||||||
m.list.Title = "Choose a list of commands"
|
m.list.Title = "Choose a list of commands"
|
||||||
m.list.SetItems(cmdListKeysToList(m.commands))
|
m.list.SetItems(cmdListKeysToList(m.commands))
|
||||||
|
m.list.Select(m.categoryIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user