From 4cc5609d8b9d79d44a7159d9d779cdb3ccdbef0e Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 21 Jul 2024 01:09:39 +0900 Subject: [PATCH] Fix invalid highlighting of truncated multi-line items --- src/terminal.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/terminal.go b/src/terminal.go index 4acb041..302a534 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -2275,6 +2275,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat finalLineNum := lineNum topCutoff := false + skipLines := 0 wrapped := false if t.multiLine || t.wrap { // Cut off the upper lines in the 'default' layout @@ -2287,7 +2288,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat wrapped = true } - lines = lines[len(lines)-maxLines:] + skipLines = len(lines) - maxLines topCutoff = true } } @@ -2323,6 +2324,10 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat } } from += len(line) + if lineOffset < skipLines { + continue + } + actualLineOffset := lineOffset - skipLines var maxe int for _, offset := range offsets { @@ -2333,7 +2338,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat actualLineNum := lineNum if t.layout == layoutDefault { - actualLineNum = (lineNum - lineOffset) + (numItemLines - lineOffset) - 1 + actualLineNum = (lineNum - actualLineOffset) + (numItemLines - actualLineOffset) - 1 } t.move(actualLineNum, 0, forceRedraw) @@ -2348,13 +2353,13 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat marker = markerTop } } else { - if lineOffset == 0 { // First line + if actualLineOffset == 0 { // First line if topCutoff { marker = markerMiddle } else { marker = markerTop } - } else if lineOffset == numItemLines-1 { // Last line + } else if actualLineOffset == numItemLines-1 { // Last line if topCutoff || !overflow { marker = markerBottom } else {