From f99c59b6d577c621c424d0d9228073b2df2cdd5d Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 19 Oct 2023 20:13:00 +0200 Subject: [PATCH] Fall back to WithWaitingStatus if item is scrolled out of view --- pkg/gui/context/list_context_trait.go | 13 +++++++++++++ pkg/gui/context/list_view_model.go | 10 +++++++++- pkg/gui/controllers/helpers/inline_status_helper.go | 4 ++-- pkg/gui/filetree/commit_file_tree.go | 6 ++++++ pkg/gui/filetree/file_tree.go | 7 +++++++ pkg/gui/types/context.go | 2 ++ 6 files changed, 39 insertions(+), 3 deletions(-) diff --git a/pkg/gui/context/list_context_trait.go b/pkg/gui/context/list_context_trait.go index cdc20a85b..ca3b3254f 100644 --- a/pkg/gui/context/list_context_trait.go +++ b/pkg/gui/context/list_context_trait.go @@ -97,3 +97,16 @@ func (self *ListContextTrait) OnSearchSelect(selectedLineIdx int) error { self.GetList().SetSelectedLineIdx(selectedLineIdx) return self.HandleFocus(types.OnFocusOpts{}) } + +func (self *ListContextTrait) IsItemVisible(item types.HasUrn) bool { + startIdx, length := self.GetViewTrait().ViewPortYBounds() + selectionStart := self.ViewIndexToModelIndex(startIdx) + selectionEnd := self.ViewIndexToModelIndex(startIdx + length) + for i := selectionStart; i < selectionEnd; i++ { + iterItem := self.GetList().GetItem(i) + if iterItem != nil && iterItem.URN() == item.URN() { + return true + } + } + return false +} diff --git a/pkg/gui/context/list_view_model.go b/pkg/gui/context/list_view_model.go index b70330d7d..22416bff1 100644 --- a/pkg/gui/context/list_view_model.go +++ b/pkg/gui/context/list_view_model.go @@ -1,6 +1,9 @@ package context -import "github.com/jesseduffield/lazygit/pkg/gui/context/traits" +import ( + "github.com/jesseduffield/lazygit/pkg/gui/context/traits" + "github.com/jesseduffield/lazygit/pkg/gui/types" +) type ListViewModel[T any] struct { *traits.ListCursor @@ -36,3 +39,8 @@ func (self *ListViewModel[T]) GetItems() []T { func Zero[T any]() T { return *new(T) } + +func (self *ListViewModel[T]) GetItem(index int) types.HasUrn { + item := self.getModel()[index] + return any(item).(types.HasUrn) +} diff --git a/pkg/gui/controllers/helpers/inline_status_helper.go b/pkg/gui/controllers/helpers/inline_status_helper.go index 7417ee5c9..7368986bd 100644 --- a/pkg/gui/controllers/helpers/inline_status_helper.go +++ b/pkg/gui/controllers/helpers/inline_status_helper.go @@ -64,10 +64,10 @@ func (self inlineStatusHelperTask) Continue() { } func (self *InlineStatusHelper) WithInlineStatus(opts InlineStatusOpts, f func(gocui.Task) error) { - context := self.c.ContextForKey(opts.ContextKey) + context := self.c.ContextForKey(opts.ContextKey).(types.IListContext) view := context.GetView() visible := view.Visible && self.windowHelper.TopViewInWindow(context.GetWindowName()) == view - if visible { + if visible && context.IsItemVisible(opts.Item) { self.c.OnWorker(func(task gocui.Task) { self.start(opts) diff --git a/pkg/gui/filetree/commit_file_tree.go b/pkg/gui/filetree/commit_file_tree.go index 593899443..2593828ee 100644 --- a/pkg/gui/filetree/commit_file_tree.go +++ b/pkg/gui/filetree/commit_file_tree.go @@ -2,6 +2,7 @@ package filetree import ( "github.com/jesseduffield/lazygit/pkg/commands/models" + "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/samber/lo" "github.com/sirupsen/logrus" ) @@ -69,6 +70,11 @@ func (self *CommitFileTree) Len() int { return self.tree.Size(self.collapsedPaths) - 1 // ignoring root } +func (self *CommitFileTree) GetItem(index int) types.HasUrn { + // Unimplemented because we don't yet need to show inlines statuses in commit file views + return nil +} + func (self *CommitFileTree) GetAllFiles() []*models.CommitFile { return self.getFiles() } diff --git a/pkg/gui/filetree/file_tree.go b/pkg/gui/filetree/file_tree.go index 45cfeed40..9d3bb580d 100644 --- a/pkg/gui/filetree/file_tree.go +++ b/pkg/gui/filetree/file_tree.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/jesseduffield/lazygit/pkg/commands/models" + "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/samber/lo" "github.com/sirupsen/logrus" ) @@ -24,6 +25,7 @@ type ITree[T any] interface { ToggleShowTree() GetIndexForPath(path string) (int, bool) Len() int + GetItem(index int) types.HasUrn SetTree() IsCollapsed(path string) bool ToggleCollapsed(path string) @@ -139,6 +141,11 @@ func (self *FileTree) Len() int { return self.tree.Size(self.collapsedPaths) - 1 // ignoring root } +func (self *FileTree) GetItem(index int) types.HasUrn { + // Unimplemented because we don't yet need to show inlines statuses in commit file views + return nil +} + func (self *FileTree) GetAllFiles() []*models.File { return self.getFiles() } diff --git a/pkg/gui/types/context.go b/pkg/gui/types/context.go index aca694228..82f03c70f 100644 --- a/pkg/gui/types/context.go +++ b/pkg/gui/types/context.go @@ -136,6 +136,7 @@ type IListContext interface { Context GetSelectedItemId() string + IsItemVisible(item HasUrn) bool GetList() IList ViewIndexToModelIndex(int) int @@ -215,6 +216,7 @@ type IController interface { type IList interface { IListCursor Len() int + GetItem(index int) HasUrn } type IListCursor interface {