diff options
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() |
