Skip to content

Commit

Permalink
Fix invalid highlighting of truncated multi-line items
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed Jul 20, 2024
1 parent 50fa90d commit 4cc5609
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)

Expand All @@ -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 {
Expand Down

0 comments on commit 4cc5609

Please sign in to comment.