Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add an option to begin at the top of the list (fix #126) #130

Merged
merged 4 commits into from
Nov 23, 2021
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
6 changes: 6 additions & 0 deletions fuzzyfinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ func (f *finder) initFinder(items []string, matched []matching.Matched, opt opt)
f.state.items = items
f.state.matched = matched
f.state.allMatched = matched

if opt.beginAtTop {
f.state.cursorY = len(f.state.matched) - 1
f.state.y = len(f.state.matched) - 1
}

if !isInTesting() {
f.drawTimer = time.AfterFunc(0, func() {
f._draw()
Expand Down
20 changes: 20 additions & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type opt struct {
hotReload bool
promptString string
header string
beginAtTop bool
}

type mode int
Expand Down Expand Up @@ -58,6 +59,25 @@ func WithHotReload() Option {
}
}

type cursorPosition int

const (
CursorPositionBottom cursorPosition = iota
CursorPositionTop
)

// WithCursorPosition sets the initial position of the cursor
func WithCursorPosition(position cursorPosition) Option {
return func(o *opt) {
switch position {
case CursorPositionTop:
o.beginAtTop = true
case CursorPositionBottom:
o.beginAtTop = false
}
}
}

// WithPromptString changes the prompt string. The default value is "> ".
func WithPromptString(s string) Option {
return func(o *opt) {
Expand Down