From d30e37434eb28c456c1897c64a4e307137fda5dc Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 11 Dec 2024 18:10:31 +0900 Subject: [PATCH] Less flickering of the candidate list when resizing the preview window --- src/terminal.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/terminal.go b/src/terminal.go index 2ab6782..1b3efde 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -2161,7 +2161,7 @@ func (t *Terminal) printItem(result Result, line int, maxLine int, index int, cu } maxWidth := t.window.Width() - (t.pointerLen + t.markerLen + 1) - postTask := func(lineNum int, width int, wrapped bool) { + postTask := func(lineNum int, width int, wrapped bool, forceRedraw bool) { if (current || selected) && t.highlightLine { color := tui.ColSelected if current { @@ -2176,7 +2176,12 @@ func (t *Terminal) printItem(result Result, line int, maxLine int, index int, cu } newLine.width = maxWidth } else { - fillSpaces := t.prevLines[lineNum].width - width + var fillSpaces int + if forceRedraw { + fillSpaces = maxWidth - width + } else { + fillSpaces = t.prevLines[lineNum].width - width + } if wrapped { fillSpaces -= t.wrapSignWidth } @@ -2288,7 +2293,7 @@ func (t *Terminal) overflow(runes []rune, max int) bool { return t.displayWidthWithLimit(runes, 0, max) > max } -func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMatch tui.ColorPair, current bool, match bool, lineNum int, maxLineNum int, forceRedraw bool, preTask func(markerClass), postTask func(int, int, bool)) int { +func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMatch tui.ColorPair, current bool, match bool, lineNum int, maxLineNum int, forceRedraw bool, preTask func(markerClass), postTask func(int, int, bool, bool)) int { var displayWidth int item := result.item matchOffsets := []Offset{} @@ -2381,7 +2386,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat if t.layout == layoutDefault { actualLineNum = (lineNum - actualLineOffset) + (numItemLines - actualLineOffset) - 1 } - t.move(actualLineNum, 0, forceRedraw) + t.move(actualLineNum, 0, forceRedraw && postTask == nil) if preTask != nil { var marker markerClass @@ -2485,7 +2490,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat t.printColoredString(t.window, line, offsets, colBase) if postTask != nil { - postTask(actualLineNum, displayWidth, wasWrapped) + postTask(actualLineNum, displayWidth, wasWrapped, forceRedraw) } else { t.markOtherLine(actualLineNum) }