1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-13 13:59:06 +02:00

Fall back to WithWaitingStatus if item is scrolled out of view

This commit is contained in:
Stefan Haller 2023-10-19 20:13:00 +02:00
parent 0fd4983c66
commit f99c59b6d5
6 changed files with 39 additions and 3 deletions

View File

@ -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
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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()
}

View File

@ -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()
}

View File

@ -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 {