1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03: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)
}