diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2025-01-16 10:05:26 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2025-01-16 10:06:11 +0900 |
| commit | 13135108906fce00dab5a403bf308e19382e630e (patch) | |
| tree | 4d31ed91c85e747f5454b20ef7f0970c1bd0c7db /src | |
| parent | b712f2bb6a5c1eed5661072604e308951ef655f2 (diff) | |
| download | fzf-13135108906fce00dab5a403bf308e19382e630e.tar.gz | |
Do not apply nth style when the whole range is covered
Diffstat (limited to 'src')
| -rw-r--r-- | src/terminal.go | 21 | ||||
| -rw-r--r-- | src/tokenizer.go | 4 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/terminal.go b/src/terminal.go index 7e7de9d6..2889bf01 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -2724,8 +2724,27 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat } sort.Sort(ByOrder(charOffsets)) } + + wholeCovered := len(t.nthCurrent) == 0 + for _, nth := range t.nthCurrent { + // Do we still want to apply a different style when the current nth + // covers the whole string? Probably not. And we can simplify the logic. + if nth.IsFull() { + wholeCovered = true + break + } + } + // But if 'nth' is set to 'regular', it's a sign that you're applying + // a different style to the rest of the string. e.g. 'nth:regular,fg:dim' + // In this case, we still need to apply and clear the style. + // We do the same when postTask is nil, which means we're printing header lines. + if t.nthAttr == tui.AttrRegular && wholeCovered || postTask == nil { + if t.nthAttr == tui.AttrRegular { + colBase = colBase.WithAttr(t.nthAttr) + } + } var nthOffsets []Offset - if len(t.nthCurrent) > 0 && t.nthAttr > 0 && postTask != nil { + if !wholeCovered && t.nthAttr > 0 && postTask != nil { var tokens []Token if item.transformed != nil { tokens = item.transformed.tokens diff --git a/src/tokenizer.go b/src/tokenizer.go index fade1d10..e5a8e977 100644 --- a/src/tokenizer.go +++ b/src/tokenizer.go @@ -18,6 +18,10 @@ type Range struct { end int } +func (r Range) IsFull() bool { + return r.begin == rangeEllipsis && r.end == rangeEllipsis +} + func RangesToString(ranges []Range) string { strs := []string{} for _, r := range ranges { |
