Skip to content

Commit

Permalink
Merge pull request #53 from knightpp/add-selected-option
Browse files Browse the repository at this point in the history
  • Loading branch information
koki-develop committed May 14, 2023
2 parents 730cfd3 + 9d054e6 commit db5632c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fzf.go
Expand Up @@ -12,6 +12,7 @@ import (
var defaultFindOption = findOption{
itemPrefixFunc: nil,
previewWindowFunc: nil,
preselectAll: false,
}

// Fuzzy Finder.
Expand Down Expand Up @@ -63,6 +64,12 @@ func (fzf *FZF) Find(items interface{}, itemFunc func(i int) string, opts ...Fin
}
fzf.model.loadItems(is)
fzf.model.setFindOption(&findOption)
if fzf.model.option.noLimit && findOption.preselectAll {
fzf.model.choices = make([]int, is.Len())
for i := 0; i < is.Len(); i++ {
fzf.model.choices[i] = i
}
}

if _, err := fzf.program.Run(); err != nil {
return nil, err
Expand Down Expand Up @@ -103,6 +110,7 @@ type FindOption func(o *findOption)
type findOption struct {
itemPrefixFunc func(i int) string
previewWindowFunc func(i, width, height int) string
preselectAll bool
}

// WithItemPrefix sets the prefix function of the item.
Expand All @@ -118,3 +126,9 @@ func WithPreviewWindow(f func(i, width, height int) string) FindOption {
o.previewWindowFunc = f
}
}

func WithPreselectAll(preselect bool) FindOption {
return func(o *findOption) {
o.preselectAll = preselect
}
}

0 comments on commit db5632c

Please sign in to comment.