Fix nth highlighting
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fix #4222
authored by Junegunn Choi · committed by Junegunn Choi · parent bbe1721 · Browse files · 5 files·+8 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+8 added−10 removed
- other:+8 added−10 removed
Provenance
- Commit
62e0a28- Tree
83c14a0- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
bbe1721
5 files changed+8 added−10 removed
modified:src/core.go+3 added-5 removed
193 unmodified lines194 }195 }196 197 nth := opts.Nth198- nthRevision := 0198+ inputRevision := revision{}199+ snapshotRevision := revision{}200 patternCache := make(map[string]*Pattern)201 patternBuilder := func(runes []rune) *Pattern {202 return BuildPattern(cache, patternCache,203 opts.Fuzzy, opts.FuzzyAlgo, opts.Extended, opts.Case, opts.Normalize, forward, withPos,203- opts.Filter == nil, nth, opts.Delimiter, nthRevision, runes)204+ opts.Filter == nil, nth, opts.Delimiter, inputRevision, runes)205 }205- inputRevision := revision{}206- snapshotRevision := revision{}206 matcher := NewMatcher(cache, patternBuilder, sort, opts.Tac, eventBox, inputRevision)207 208 // Filtering mode209 if opts.Filter != nil {170 unmodified lines380 changed = val.changed381 if val.nth != nil {382 // Change nth and clear caches383 nth = *val.nth385- nthRevision++384 patternCache = make(map[string]*Pattern)385 cache.Clear()386 inputRevision.bumpMinor()387 }90 unmodified linesmodified:src/item.go+1 added-1 removed
7 unmodified lines8 9 type transformed struct {10 // Because nth can be changed dynamically by change-nth action, we need to11 // keep the revision number at the time of transformation.12- revision int12+ revision revision13 tokens []Token14 }15 16 // Item represents each input line. 56 bytes.37 unmodified linesmodified:src/pattern_test.go+1 added-1 removed
66 unmodified lines67 func buildPattern(fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case, normalize bool, forward bool,68 withPos bool, cacheable bool, nth []Range, delimiter Delimiter, runes []rune) *Pattern {69 return BuildPattern(NewChunkCache(), make(map[string]*Pattern),70 fuzzy, fuzzyAlgo, extended, caseMode, normalize, forward,71- withPos, cacheable, nth, delimiter, 0, runes)71+ withPos, cacheable, nth, delimiter, revision{}, runes)72 }73 74 func TestExact(t *testing.T) {75 pattern := buildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, false, true,126 unmodified linesmodified:src/pattern.go+2 added-2 removed
58 unmodified lines59 cacheable bool60 cacheKey string61 delimiter Delimiter62 nth []Range63- revision int63+ revision revision64 procFun map[termType]algo.Algo65 cache *ChunkCache66 }67 4 unmodified lines72 }73 74 // BuildPattern builds Pattern object from the given arguments75 func BuildPattern(cache *ChunkCache, patternCache map[string]*Pattern, fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case, normalize bool, forward bool,76- withPos bool, cacheable bool, nth []Range, delimiter Delimiter, revision int, runes []rune) *Pattern {76+ withPos bool, cacheable bool, nth []Range, delimiter Delimiter, revision revision, runes []rune) *Pattern {77 78 var asString string79 if extended {80 asString = strings.TrimLeft(string(runes), " ")344 unmodified linesmodified:src/terminal.go+1 added-1 removed
2930 unmodified lines2931 colBase = colBase.WithAttr(t.nthAttr)2932 }2933 if !wholeCovered && t.nthAttr > 0 {2934 var tokens []Token2935- if item.transformed != nil {2935+ if item.transformed != nil && item.transformed.revision == t.merger.revision {2936 tokens = item.transformed.tokens2937 } else {2938 tokens = Transform(Tokenize(item.text.ToString(), t.delimiter), t.nthCurrent)2939 }3289 unmodified lines