Add change-nth action

Example:
  # Start with --nth 1, then 2, then 3, then back to the default, 1
  echo 'foo foobar foobarbaz' | fzf --bind 'space:change-nth(2|3|)' --nth 1 -q foo

Close #4172
Close #3109
This commit is contained in:
Junegunn Choi
2025-01-13 00:13:31 +09:00
parent 6f943112a9
commit d83eb2800a
7 changed files with 163 additions and 102 deletions

View File

@@ -190,11 +190,13 @@ func Run(opts *Options) (int, error) {
forward = true
}
}
nth := opts.Nth
patternCache := make(map[string]*Pattern)
patternBuilder := func(runes []rune) *Pattern {
return BuildPattern(cache, patternCache,
opts.Fuzzy, opts.FuzzyAlgo, opts.Extended, opts.Case, opts.Normalize, forward, withPos,
opts.Filter == nil, opts.Nth, opts.Delimiter, runes)
opts.Filter == nil, nth, opts.Delimiter, runes)
}
inputRevision := revision{}
snapshotRevision := revision{}
@@ -373,6 +375,12 @@ func Run(opts *Options) (int, error) {
command = val.command
environ = val.environ
changed = val.changed
if val.nth != nil {
// Change nth and clear caches
nth = *val.nth
patternCache = make(map[string]*Pattern)
inputRevision.bumpMajor()
}
if command != nil {
useSnapshot = val.sync
}