Commit c3eba1630c
Unsigned
Layout: unified · split
internal/selection_menu.go +11 −8
| @@ -16,13 +16,13 @@ type SelectionOption struct { | ||
| 16 | 16 | |
| 17 | 17 | // Model represents the application state for the selection prompt |
| 18 | 18 | type Model struct { |
| 19 | options map[string]string | |
| 20 | filter string | |
| 21 | filteredKeys []SelectionOption | |
| 22 | selected int | |
| 23 | terminalWidth int | |
| 19 | options map[string]string | |
| 20 | filter string | |
| 21 | filteredKeys []SelectionOption | |
| 22 | selected int | |
| 23 | terminalWidth int | |
| 24 | 24 | terminalHeight int |
| 25 | scrollOffset int // Track the topmost visible item | |
| 25 | scrollOffset int // Track the topmost visible item | |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | // Init initializes the model |
| @@ -44,7 +44,9 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
| 44 | 44 | case tea.KeyMsg: |
| 45 | 45 | switch msg.String() { |
| 46 | 46 | case "ctrl+c", "q": |
| 47 | return m, tea.Quit | |
| 47 | // Return quit selection option instead of quitting the program | |
| 48 | m.filteredKeys[m.selected] = SelectionOption{"quit", "-1"} | |
| 49 | return m, tea.Quit // Properly exit the program | |
| 48 | 50 | case "backspace": |
| 49 | 51 | if len(m.filter) > 0 { |
| 50 | 52 | m.filter = m.filter[:len(m.filter)-1] |
| @@ -73,6 +75,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
| 73 | 75 | case "enter": |
| 74 | 76 | if m.filteredKeys[m.selected].Key == "add_new" { |
| 75 | 77 | fmt.Println("Adding a new anime...") |
| 78 | m.filteredKeys[m.selected] = SelectionOption{"add_new", "0"} | |
| 76 | 79 | return m, tea.Quit |
| 77 | 80 | } |
| 78 | 81 | return m, tea.Quit |
| @@ -86,7 +89,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
| 86 | 89 | |
| 87 | 90 | if updateFilter { |
| 88 | 91 | m.filterOptions() |
| 89 | m.selected = 0 // Reset selection to the first item after filtering | |
| 92 | m.selected = 0 // Reset selection to the first item after filtering | |
| 90 | 93 | m.scrollOffset = 0 // Reset scrolling |
| 91 | 94 | } |
| 92 | 95 | |