Fix invalid highlighting of truncated multi-line items

This commit is contained in:
Junegunn Choi 2024-07-21 01:09:39 +09:00
parent 50fa90dfb8
commit 4cc5609d8b
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -2275,6 +2275,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
finalLineNum := lineNum finalLineNum := lineNum
topCutoff := false topCutoff := false
skipLines := 0
wrapped := false wrapped := false
if t.multiLine || t.wrap { if t.multiLine || t.wrap {
// Cut off the upper lines in the 'default' layout // 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 wrapped = true
} }
lines = lines[len(lines)-maxLines:] skipLines = len(lines) - maxLines
topCutoff = true topCutoff = true
} }
} }
@ -2323,6 +2324,10 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
} }
} }
from += len(line) from += len(line)
if lineOffset < skipLines {
continue
}
actualLineOffset := lineOffset - skipLines
var maxe int var maxe int
for _, offset := range offsets { for _, offset := range offsets {
@ -2333,7 +2338,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
actualLineNum := lineNum actualLineNum := lineNum
if t.layout == layoutDefault { if t.layout == layoutDefault {
actualLineNum = (lineNum - lineOffset) + (numItemLines - lineOffset) - 1 actualLineNum = (lineNum - actualLineOffset) + (numItemLines - actualLineOffset) - 1
} }
t.move(actualLineNum, 0, forceRedraw) t.move(actualLineNum, 0, forceRedraw)
@ -2348,13 +2353,13 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
marker = markerTop marker = markerTop
} }
} else { } else {
if lineOffset == 0 { // First line if actualLineOffset == 0 { // First line
if topCutoff { if topCutoff {
marker = markerMiddle marker = markerMiddle
} else { } else {
marker = markerTop marker = markerTop
} }
} else if lineOffset == numItemLines-1 { // Last line } else if actualLineOffset == numItemLines-1 { // Last line
if topCutoff || !overflow { if topCutoff || !overflow {
marker = markerBottom marker = markerBottom
} else { } else {