From d83eb2800a09d86e17c0339d86bd1f22f68164a8 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 13 Jan 2025 00:13:31 +0900 Subject: 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 --- src/core.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/core.go') diff --git a/src/core.go b/src/core.go index 89f40ceb..35a143fe 100644 --- a/src/core.go +++ b/src/core.go @@ -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 } -- cgit v1.2.3