diff options
| author | ewy <ewy0@protonmail.com> | 2026-05-02 16:23:36 +0200 |
|---|---|---|
| committer | ewy <ewy0@protonmail.com> | 2026-05-02 16:23:36 +0200 |
| commit | c01a06e38d0b0331f459cd439ce7706ef1556e50 (patch) | |
| tree | 8bee63be92b6301d169be6113dfc3bbf16d37c9e /menu/input.go | |
| parent | 1e932e7015ac9d21a1f92ad57cd0c109f58bb29f (diff) | |
* fix infinite loop on not found
* add bash tab completion script (will have install option in the future)
* add search to tui (bound to / and ?)
Diffstat (limited to 'menu/input.go')
| -rw-r--r-- | menu/input.go | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/menu/input.go b/menu/input.go index cd07543..e2e35b3 100644 --- a/menu/input.go +++ b/menu/input.go @@ -3,8 +3,32 @@ package menu import tea "github.com/charmbracelet/bubbletea" func (m *Model) HandleInput(msg tea.KeyMsg) (tea.Cmd, error) { + + if m.Search.Focused() { + var cmd tea.Cmd + switch msg.String() { + case "ctrl+c": + m.Search.SetValue("") + m.Search.Blur() + case "ctrl+d": + m.Search.Blur() + case "enter": + m.Search.Blur() + default: + result, c := m.Search.Update(msg) + cmd = c + m.Search = result + } + return cmd, nil + } + var cmd tea.Cmd switch msg.String() { + case "/": + m.Search.SetValue("") + fallthrough + case "?": + return m.Search.Focus(), nil case "i", "I": if m.Alt { m.Alt = false @@ -23,6 +47,10 @@ func (m *Model) HandleInput(msg tea.KeyMsg) (tea.Cmd, error) { m.Index-- case "down", "j": m.Index++ + case "n": + m.LeapFilter(1) + case "N": + m.LeapFilter(-1) case "q", "esc", "ctrl+c": m.Cancel = true return tea.Quit, nil @@ -31,11 +59,28 @@ func (m *Model) HandleInput(msg tea.KeyMsg) (tea.Cmd, error) { return tea.Quit, nil } - m.Validate() + _ = m.Validate() return cmd, nil } +func (m *Model) LeapFilter(direction int) { + startIndex := m.Index + for { + m.Index += direction + clamped := m.Validate() + if clamped { + m.Index = startIndex + return + } + + source, target := m.Result() + if m.Highlights(source, target) { + return + } + } +} + func (m *Model) Leap(direction int) { for { source, target := m.Result() |
