Commit 1695850319

1695850319b0ecd9518a72d27204919dbe26a304

parent: e8f271e504

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-18 09:18 UTC

fix selection bug

Layout: unified · split

internal/selection_menu.go +15
@@ -27,6 +27,9 @@ func (m Model) Init() tea.Cmd {
2727
2828// Update handles user input and updates the model
2929func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
30 // Only filter options if a key press modifies the filter
31 updateFilter := false
32
3033 switch msg := msg.(type) {
3134 case tea.KeyMsg:
3235 switch msg.String() {
@@ -35,12 +38,15 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
3538 case "backspace":
3639 if len(m.filter) > 0 {
3740 m.filter = m.filter[:len(m.filter)-1]
41 updateFilter = true // Mark for updating the filter
3842 }
3943 case "down":
44 // Move cursor down within bounds
4045 if m.selected < len(m.filteredKeys)-1 {
4146 m.selected++
4247 }
4348 case "up":
49 // Move cursor up within bounds
4450 if m.selected > 0 {
4551 m.selected--
4652 }
@@ -49,13 +55,22 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
4955 default:
5056 if msg.String() != "" {
5157 m.filter += msg.String()
58 updateFilter = true // Mark for updating the filter
5259 }
5360 }
61 }
62
63 // Only filter options if the filter was actually modified
64 if updateFilter {
5465 m.filterOptions()
66 // Reset selected index after filtering
67 m.selected = 0
5568 }
69
5670 return m, nil
5771}
5872
73
5974// View renders the UI
6075func (m Model) View() string {
6176 var b strings.Builder