Skip to content

Commit

Permalink
Do not apply nth style when the whole range is covered
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed Jan 16, 2025
1 parent b712f2b commit 1313510
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Also, fzf now offers "style presets" for quick customization, which can be activ
# With 'change-nth'. The current nth option is exported as $FZF_NTH.
ps -ef | fzf --reverse --header-lines 1 --header-border bottom --input-border \
--color nth:regular,fg:dim,current-fg:dim \
--nth 8.. --bind 'ctrl-n:change-nth(1|2|3|4|5|6|7|)' \
--bind 'ctrl-n:change-nth(8..|1|2|3|4|5|6|7|)' \
--bind 'result:transform-prompt:echo "${FZF_NTH}> "'
```
- A single-character delimiter is now treated as a plain string delimiter rather than a regular expression delimiter, even if it's a regular expression meta-character.
Expand Down
21 changes: 20 additions & 1 deletion src/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/tokenizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1313510

Please sign in to comment.