From 5ed87ffcb920f8311cfd29dee0575e6c64755314 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 26 Jun 2025 20:47:57 +0900 Subject: [PATCH] Fix highlight offsets of multi-line entries Fix regression from 4811e52a --- src/ansi.go | 1 + src/core.go | 2 +- src/terminal.go | 9 ++------- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ansi.go b/src/ansi.go index ba4b3d45..1311620d 100644 --- a/src/ansi.go +++ b/src/ansi.go @@ -278,6 +278,7 @@ func extractColor(str string, state *ansiState, proc func(string, *ansiState) bo if code == "\n" { output.WriteRune('\n') + runeCount++ // Full-background marker if newState.lbg >= 0 { marker := newState diff --git a/src/core.go b/src/core.go index 2fca98fb..ac42143d 100644 --- a/src/core.go +++ b/src/core.go @@ -81,7 +81,7 @@ func Run(opts *Options) (int, error) { lineAnsiState = newState // Full line background is found. Add a special marker. - if !opts.ReadZero && offsets != nil && newState != nil && len(*offsets) > 0 && newState.lbg >= 0 { + if offsets != nil && newState != nil && len(*offsets) > 0 && newState.lbg >= 0 { marker := (*offsets)[len(*offsets)-1] marker.offset[0] = marker.offset[1] marker.color.bg = newState.lbg diff --git a/src/terminal.go b/src/terminal.go index f5ded439..9c627e12 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -3399,13 +3399,8 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat finalLineNum = lineNum offsets := []colorOffset{} lbg := tui.NoColorPair() - var lineLen int for idx, offset := range allOffsets { - lineLen = len(line) - if lineLen > 0 && line[lineLen-1] == '\n' { - lineLen-- - } - lineEnd := int32(from + lineLen) + lineEnd := int32(from + len(line)) if offset.offset[0] >= lineEnd { if offset.IsFullBgMarker(lineEnd) { lbg = offset.color @@ -3441,7 +3436,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat break } } - from += lineLen + from += len(line) if lineOffset < skipLines { continue }