summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2025-02-06 19:56:40 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2025-02-06 19:57:39 +0900
commit62e0a2824a9ed2783fee54f53dd258a2bc3ed795 (patch)
tree83c14a09b9f24ec138835ac9536c0aada10e4505 /src
parentbbe1721a1883426f639c1efe6afef1d3e6c25181 (diff)
downloadfzf-62e0a2824a9ed2783fee54f53dd258a2bc3ed795.tar.gz
Fix nth highlighting
Fix #4222
Diffstat (limited to 'src')
-rw-r--r--src/core.go8
-rw-r--r--src/item.go2
-rw-r--r--src/pattern.go4
-rw-r--r--src/pattern_test.go2
-rw-r--r--src/terminal.go2
5 files changed, 8 insertions, 10 deletions
diff --git a/src/core.go b/src/core.go
index 71cf04da..cad139dd 100644
--- a/src/core.go
+++ b/src/core.go
@@ -195,15 +195,14 @@ func Run(opts *Options) (int, error) {
}
nth := opts.Nth
- nthRevision := 0
+ inputRevision := revision{}
+ snapshotRevision := revision{}
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, nth, opts.Delimiter, nthRevision, runes)
+ opts.Filter == nil, nth, opts.Delimiter, inputRevision, runes)
}
- inputRevision := revision{}
- snapshotRevision := revision{}
matcher := NewMatcher(cache, patternBuilder, sort, opts.Tac, eventBox, inputRevision)
// Filtering mode
@@ -382,7 +381,6 @@ func Run(opts *Options) (int, error) {
if val.nth != nil {
// Change nth and clear caches
nth = *val.nth
- nthRevision++
patternCache = make(map[string]*Pattern)
cache.Clear()
inputRevision.bumpMinor()
diff --git a/src/item.go b/src/item.go
index 1943486f..ca32f1bd 100644
--- a/src/item.go
+++ b/src/item.go
@@ -9,7 +9,7 @@ import (
type transformed struct {
// Because nth can be changed dynamically by change-nth action, we need to
// keep the revision number at the time of transformation.
- revision int
+ revision revision
tokens []Token
}
diff --git a/src/pattern.go b/src/pattern.go
index dd9c5292..29149fe7 100644
--- a/src/pattern.go
+++ b/src/pattern.go
@@ -60,7 +60,7 @@ type Pattern struct {
cacheKey string
delimiter Delimiter
nth []Range
- revision int
+ revision revision
procFun map[termType]algo.Algo
cache *ChunkCache
}
@@ -73,7 +73,7 @@ func init() {
// BuildPattern builds Pattern object from the given arguments
func BuildPattern(cache *ChunkCache, patternCache map[string]*Pattern, fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case, normalize bool, forward bool,
- withPos bool, cacheable bool, nth []Range, delimiter Delimiter, revision int, runes []rune) *Pattern {
+ withPos bool, cacheable bool, nth []Range, delimiter Delimiter, revision revision, runes []rune) *Pattern {
var asString string
if extended {
diff --git a/src/pattern_test.go b/src/pattern_test.go
index 0f0632cd..24b17744 100644
--- a/src/pattern_test.go
+++ b/src/pattern_test.go
@@ -68,7 +68,7 @@ func buildPattern(fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case,
withPos bool, cacheable bool, nth []Range, delimiter Delimiter, runes []rune) *Pattern {
return BuildPattern(NewChunkCache(), make(map[string]*Pattern),
fuzzy, fuzzyAlgo, extended, caseMode, normalize, forward,
- withPos, cacheable, nth, delimiter, 0, runes)
+ withPos, cacheable, nth, delimiter, revision{}, runes)
}
func TestExact(t *testing.T) {
diff --git a/src/terminal.go b/src/terminal.go
index d91bff48..e138b62c 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -2932,7 +2932,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
}
if !wholeCovered && t.nthAttr > 0 {
var tokens []Token
- if item.transformed != nil {
+ if item.transformed != nil && item.transformed.revision == t.merger.revision {
tokens = item.transformed.tokens
} else {
tokens = Transform(Tokenize(item.text.ToString(), t.delimiter), t.nthCurrent)