From d0466fa77714cccae6875facafb4a7d49e3f958e Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 2 Nov 2023 21:00:07 +0900 Subject: [PATCH] Fix regression where tcell renderer not clearing the preview window --- src/terminal.go | 11 ++++++++--- src/tui/light.go | 4 ++++ src/tui/tcell.go | 5 +++++ src/tui/tui.go | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/terminal.go b/src/terminal.go index 878e3d9a..a8a607f4 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -1942,9 +1942,14 @@ func (t *Terminal) renderPreviewArea(unchanged bool) { t.pwindow.MoveAndClear(0, 0) // Clear scroll offset display } else { t.previewed.filled = false - // We don't erase the window here to avoid flickering during scroll - t.pwindow.DrawBorder() - t.pwindow.Move(0, 0) + // We don't erase the window here to avoid flickering during scroll. + // However, tcell renderer uses double-buffering technique and there's no + // flickering. So we just erase the window and make the rest of the code + // simpler. + if !t.pwindow.EraseMaybe() { + t.pwindow.DrawBorder() + t.pwindow.Move(0, 0) + } } height := t.pwindow.Height() diff --git a/src/tui/light.go b/src/tui/light.go index d26a48f6..e5950cde 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -1109,3 +1109,7 @@ func (w *LightWindow) Erase() { w.FinishFill() w.Move(0, 0) } + +func (w *LightWindow) EraseMaybe() bool { + return false +} diff --git a/src/tui/tcell.go b/src/tui/tcell.go index d0a710a3..38641f7a 100644 --- a/src/tui/tcell.go +++ b/src/tui/tcell.go @@ -555,6 +555,11 @@ func (w *TcellWindow) Erase() { fill(w.left-1, w.top, w.width+1, w.height-1, w.normal, ' ') } +func (w *TcellWindow) EraseMaybe() bool { + w.Erase() + return true +} + func (w *TcellWindow) Enclose(y int, x int) bool { return x >= w.left && x < (w.left+w.width) && y >= w.top && y < (w.top+w.height) diff --git a/src/tui/tui.go b/src/tui/tui.go index 7ba437aa..5a5e18d6 100644 --- a/src/tui/tui.go +++ b/src/tui/tui.go @@ -526,6 +526,7 @@ type Window interface { Fill(text string) FillReturn CFill(fg Color, bg Color, attr Attr, text string) FillReturn Erase() + EraseMaybe() bool } type FullscreenRenderer struct {