Skip to content
New issue

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

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

Already on GitHub? Sign in 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 1 commit
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
8 changes: 8 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,13 @@ func WithHotReload() Option {
}
}

// WithBeginAtTop makes the selection begin at the top of the list instead of the bottom
func WithBeginAtTop() Option {
r-darwish marked this conversation as resolved.
Show resolved Hide resolved
return func(o *opt) {
o.beginAtTop = true
}
}

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