Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/ui/var_resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ func (m *mainModel) handleVarResolveKey(msg tea.KeyMsg) tea.Cmd {
return nil
case "enter":
return m.acceptVarValue()
case "up", "ctrl+p", "down", "ctrl+n", "pgup", "pgdown":
if !m.varState.isPromptOnly && m.varState.picker != nil {
m.varState.picker.HandleKey(msg)
}
return nil
case "tab":
if m.completePathFromInput() {
return nil
Expand Down
36 changes: 36 additions & 0 deletions internal/ui/var_resolve_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ui

import (
"testing"

tea "github.com/charmbracelet/bubbletea"
"github.com/gubarz/cheatmd/pkg/parser"
)

func TestVarResolveArrowKeysMoveSelection(t *testing.T) {
m := newMainModel([]*parser.Cheat{{Header: "One"}}, parser.NewCheatIndex(), nil)
items := []FilteredOption{
{Display: "alpha", Original: "alpha", SearchText: "alpha"},
{Display: "beta", Original: "beta", SearchText: "beta"},
{Display: "gamma", Original: "gamma", SearchText: "gamma"},
}
m.phase = phaseVarResolve
m.varState = &varResolveState{
isPromptOnly: false,
picker: NewPicker(items, func(opt FilteredOption, words []string) bool {
return matchesAllWords(opt.SearchText, words)
}),
}

model, _ := m.updateVarResolve(tea.KeyMsg{Type: tea.KeyDown})
got := model.(*mainModel)
if got.varState.picker.Cursor != 1 {
t.Fatalf("cursor after down = %d, want 1", got.varState.picker.Cursor)
}

model, _ = got.updateVarResolve(tea.KeyMsg{Type: tea.KeyUp})
got = model.(*mainModel)
if got.varState.picker.Cursor != 0 {
t.Fatalf("cursor after up = %d, want 0", got.varState.picker.Cursor)
}
}
Loading