summaryrefslogtreecommitdiffstats
path: root/pkg/gui/window.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-10-02 20:31:40 -0700
committerJesse Duffield <jessedduffield@gmail.com>2022-10-02 20:41:24 -0700
commite76fa5a6cb648f8c3b642d83368ea08a48ab43b0 (patch)
treeb5e7fd56f0e3bad837608c0c76c63394df308c96 /pkg/gui/window.go
parenta77aa4d75ae1f04a15257fd92f7e763b8a4215db (diff)
fix glitchy render of stale data when flicking through files and directories
Diffstat (limited to 'pkg/gui/window.go')
-rw-r--r--pkg/gui/window.go29
1 files changed, 22 insertions, 7 deletions
diff --git a/pkg/gui/window.go b/pkg/gui/window.go
index efee847e1..12cd31868 100644
--- a/pkg/gui/window.go
+++ b/pkg/gui/window.go
@@ -3,6 +3,7 @@ package gui
import (
"fmt"
+ "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/samber/lo"
@@ -70,28 +71,42 @@ func (gui *Gui) resetWindowContext(c types.Context) {
}
}
-func (gui *Gui) moveToTopOfWindow(context types.Context) {
+// moves given context's view to the top of the window and returns
+// true if the view was not already on top.
+func (gui *Gui) moveToTopOfWindow(context types.Context) bool {
view := context.GetView()
if view == nil {
- return
+ return false
}
window := context.GetWindowName()
+ topView := gui.topViewInWindow(window)
+
+ if view.Name() == topView.Name() {
+ return false
+ } else {
+ if err := gui.g.SetViewOnTopOf(view.Name(), topView.Name()); err != nil {
+ gui.Log.Error(err)
+ }
+
+ return true
+ }
+}
+
+func (gui *Gui) topViewInWindow(windowName string) *gocui.View {
// 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.
- viewNamesInWindow := gui.viewNamesInWindow(window)
+ viewNamesInWindow := gui.viewNamesInWindow(windowName)
// The views list is ordered highest-last, so we're grabbing the last view of the window
- topView := view
+ var topView *gocui.View
for _, currentView := range gui.g.Views() {
if lo.Contains(viewNamesInWindow, currentView.Name()) {
topView = currentView
}
}
- if err := gui.g.SetViewOnTopOf(view.Name(), topView.Name()); err != nil {
- gui.Log.Error(err)
- }
+ return topView
}
func (gui *Gui) viewNamesInWindow(windowName string) []string {