Reduce flicking when changing the size of the preview window with --border

(sleep 1; find .) |
    fzf --bind 'space:change-preview-window(60%|70%|80%|90%|border-left|border-right|border-vertical|border-top|border-horizontal|border-bottom|border-sharp|border-double|border-block|hidden|left|up|down|right|up|down|)' \
        --preview 'cat {}' --color bg:red,preview-bg:blue \
        --border --margin 3
This commit is contained in:
Junegunn Choi 2024-05-05 13:44:08 +09:00
parent c37cd11ca5
commit 2bd41f1330
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
2 changed files with 19 additions and 22 deletions

View File

@ -1288,7 +1288,8 @@ func (t *Terminal) resizeWindows(forcePreview bool) {
t.pborder.Close()
t.pborder = nil
}
if t.pwindow != nil {
hadPreviewWindow := t.hasPreviewWindow()
if hadPreviewWindow {
t.pwindow.Close()
t.pwindow = nil
}
@ -1387,6 +1388,9 @@ func (t *Terminal) resizeWindows(forcePreview bool) {
pwidth = util.Max(0, pwidth)
pheight = util.Max(0, pheight)
t.pwindow = t.tui.NewWindow(y, x, pwidth, pheight, true, noBorder)
if !hadPreviewWindow {
t.pwindow.Erase()
}
}
verticalPad := 2
minPreviewHeight := 3
@ -1649,7 +1653,7 @@ func (t *Terminal) printInfo() {
case infoDefault:
t.move(line+1, 0, t.separatorLen == 0)
printSpinner()
t.move(line+1, 2, false)
t.window.Print(" ") // Margin
pos = 2
case infoRight:
t.move(line+1, 0, false)
@ -1714,6 +1718,7 @@ func (t *Terminal) printInfo() {
printSeparator(fillLength, true)
}
t.window.CPrint(tui.ColInfo, output)
t.window.Print(" ") // Margin
return
}
@ -2922,6 +2927,7 @@ func (t *Terminal) Loop() {
t.initFunc()
t.termSize = t.tui.Size()
t.resizeWindows(false)
t.window.Erase()
t.printPrompt()
t.printInfo()
t.printHeader()

View File

@ -821,44 +821,32 @@ func (w *LightWindow) drawBorderHorizontal(top, bottom bool) {
color = ColPreviewBorder
}
hw := runeWidth(w.border.top)
pad := repeat(' ', w.width/hw)
w.Move(0, 0)
if top {
w.Move(0, 0)
w.CPrint(color, repeat(w.border.top, w.width/hw))
} else {
w.CPrint(color, pad)
}
for y := 1; y < w.height-1; y++ {
w.Move(y, 0)
w.CPrint(color, pad)
}
w.Move(w.height-1, 0)
if bottom {
w.Move(w.height-1, 0)
w.CPrint(color, repeat(w.border.bottom, w.width/hw))
} else {
w.CPrint(color, pad)
}
}
func (w *LightWindow) drawBorderVertical(left, right bool) {
width := w.width - 2
if !left || !right {
width++
}
vw := runeWidth(w.border.left)
color := ColBorder
if w.preview {
color = ColPreviewBorder
}
for y := 0; y < w.height; y++ {
w.Move(y, 0)
if left {
w.Move(y, 0)
w.CPrint(color, string(w.border.left))
w.CPrint(color, " ") // Margin
}
w.CPrint(color, repeat(' ', width))
if right {
w.Move(y, w.width-vw-1)
w.CPrint(color, " ") // Margin
w.CPrint(color, string(w.border.right))
}
}
@ -880,7 +868,10 @@ func (w *LightWindow) drawBorderAround(onlyHorizontal bool) {
for y := 1; y < w.height-1; y++ {
w.Move(y, 0)
w.CPrint(color, string(w.border.left))
w.CPrint(color, repeat(' ', w.width-vw*2))
w.CPrint(color, " ") // Margin
w.Move(y, w.width-vw-1)
w.CPrint(color, " ") // Margin
w.CPrint(color, string(w.border.right))
}
}