Skip to content

Commit e76fa5a

Browse files
committed
fix glitchy render of stale data when flicking through files and directories
1 parent a77aa4d commit e76fa5a

File tree

6 files changed

+69
-15
lines changed

6 files changed

+69
-15
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/integrii/flaggy v1.4.0
1919
github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68
2020
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4
21-
github.com/jesseduffield/gocui v0.3.1-0.20221001154429-72c39318a83d
21+
github.com/jesseduffield/gocui v0.3.1-0.20221003033055-3b1444b7ce1c
2222
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10
2323
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e
2424
github.com/jesseduffield/yaml v2.1.0+incompatible

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68 h1:EQP2Tv8T
7272
github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68/go.mod h1:+LLj9/WUPAP8LqCchs7P+7X0R98HiFujVFANdNaxhGk=
7373
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4 h1:GOQrmaE8i+KEdB8NzAegKYd4tPn/inM0I1uo0NXFerg=
7474
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o=
75-
github.com/jesseduffield/gocui v0.3.1-0.20221001154429-72c39318a83d h1:OTUa2dO3IvnY53QWCABkKJK9v5yvs3+uv3RMbG698S0=
76-
github.com/jesseduffield/gocui v0.3.1-0.20221001154429-72c39318a83d/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU=
75+
github.com/jesseduffield/gocui v0.3.1-0.20221003033055-3b1444b7ce1c h1:mbOoXlqOzc243zNV71pDxeiEof8IRRw2ZJzVXm/RLjc=
76+
github.com/jesseduffield/gocui v0.3.1-0.20221003033055-3b1444b7ce1c/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU=
7777
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10 h1:jmpr7KpX2+2GRiE91zTgfq49QvgiqB0nbmlwZ8UnOx0=
7878
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10/go.mod h1:aA97kHeNA+sj2Hbki0pvLslmE4CbDyhBeSSTUUnOuVo=
7979
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e h1:uw/oo+kg7t/oeMs6sqlAwr85ND/9cpO3up3VxphxY0U=

pkg/gui/main_panels.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,35 @@ func (gui *Gui) runTaskForView(view *gocui.View, task types.UpdateTask) error {
2727
}
2828

2929
func (gui *Gui) moveMainContextPairToTop(pair types.MainContextPair) {
30-
gui.setWindowContext(pair.Main)
31-
gui.moveToTopOfWindow(pair.Main)
30+
gui.moveMainContextToTop(pair.Main)
3231
if pair.Secondary != nil {
33-
gui.setWindowContext(pair.Secondary)
34-
gui.moveToTopOfWindow(pair.Secondary)
32+
gui.moveMainContextToTop(pair.Secondary)
33+
}
34+
}
35+
36+
func (gui *Gui) moveMainContextToTop(context types.Context) {
37+
gui.setWindowContext(context)
38+
39+
view := context.GetView()
40+
41+
topView := gui.topViewInWindow(context.GetWindowName())
42+
if topView == nil {
43+
gui.Log.Error("unexpected: topView is nil")
44+
return
45+
}
46+
47+
if topView != view {
48+
// We need to copy the content to avoid a flicker effect: If we're flicking
49+
// through files in the files panel, we use a different view to render the
50+
// files vs the directories, and if you select dir A, then file B, then dir
51+
// C, you'll briefly see dir A's contents again before the view is updated.
52+
// So here we're copying the content from the top window to avoid that
53+
// flicker effect.
54+
gui.g.CopyContent(topView, view)
55+
56+
if err := gui.g.SetViewOnTopOf(view.Name(), topView.Name()); err != nil {
57+
gui.Log.Error(err)
58+
}
3559
}
3660
}
3761

pkg/gui/window.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gui
33
import (
44
"fmt"
55

6+
"github.com/jesseduffield/gocui"
67
"github.com/jesseduffield/lazygit/pkg/gui/context"
78
"github.com/jesseduffield/lazygit/pkg/gui/types"
89
"github.com/samber/lo"
@@ -70,28 +71,42 @@ func (gui *Gui) resetWindowContext(c types.Context) {
7071
}
7172
}
7273

73-
func (gui *Gui) moveToTopOfWindow(context types.Context) {
74+
// moves given context's view to the top of the window and returns
75+
// true if the view was not already on top.
76+
func (gui *Gui) moveToTopOfWindow(context types.Context) bool {
7477
view := context.GetView()
7578
if view == nil {
76-
return
79+
return false
7780
}
7881

7982
window := context.GetWindowName()
8083

84+
topView := gui.topViewInWindow(window)
85+
86+
if view.Name() == topView.Name() {
87+
return false
88+
} else {
89+
if err := gui.g.SetViewOnTopOf(view.Name(), topView.Name()); err != nil {
90+
gui.Log.Error(err)
91+
}
92+
93+
return true
94+
}
95+
}
96+
97+
func (gui *Gui) topViewInWindow(windowName string) *gocui.View {
8198
// now I need to find all views in that same window, via contexts. And I guess then I need to find the index of the highest view in that list.
82-
viewNamesInWindow := gui.viewNamesInWindow(window)
99+
viewNamesInWindow := gui.viewNamesInWindow(windowName)
83100

84101
// The views list is ordered highest-last, so we're grabbing the last view of the window
85-
topView := view
102+
var topView *gocui.View
86103
for _, currentView := range gui.g.Views() {
87104
if lo.Contains(viewNamesInWindow, currentView.Name()) {
88105
topView = currentView
89106
}
90107
}
91108

92-
if err := gui.g.SetViewOnTopOf(view.Name(), topView.Name()); err != nil {
93-
gui.Log.Error(err)
94-
}
109+
return topView
95110
}
96111

97112
func (gui *Gui) viewNamesInWindow(windowName string) []string {

vendor/github.com/jesseduffield/gocui/gui.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ github.com/jesseduffield/go-git/v5/utils/merkletrie/filesystem
172172
github.com/jesseduffield/go-git/v5/utils/merkletrie/index
173173
github.com/jesseduffield/go-git/v5/utils/merkletrie/internal/frame
174174
github.com/jesseduffield/go-git/v5/utils/merkletrie/noder
175-
# github.com/jesseduffield/gocui v0.3.1-0.20221001154429-72c39318a83d
175+
# github.com/jesseduffield/gocui v0.3.1-0.20221003033055-3b1444b7ce1c
176176
## explicit; go 1.12
177177
github.com/jesseduffield/gocui
178178
# github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10

0 commit comments

Comments
 (0)