mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-27 00:51:18 +02:00
Ensure file view length is never returned as -1
This was causing issues when obtaining selected items
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -138,7 +139,8 @@ func (self *FileTree) GetAllItems() []*FileNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *FileTree) Len() int {
|
func (self *FileTree) Len() int {
|
||||||
return self.tree.Size(self.collapsedPaths) - 1 // ignoring root
|
// -1 because we're ignoring the root
|
||||||
|
return utils.Max(self.tree.Size(self.collapsedPaths)-1, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *FileTree) GetItem(index int) types.HasUrn {
|
func (self *FileTree) GetItem(index int) types.HasUrn {
|
||||||
|
@ -54,6 +54,10 @@ func (self *FileTreeViewModel) GetSelectedItemId() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *FileTreeViewModel) GetSelectedItems() ([]*FileNode, int, int) {
|
func (self *FileTreeViewModel) GetSelectedItems() ([]*FileNode, int, int) {
|
||||||
|
if self.Len() == 0 {
|
||||||
|
return nil, 0, 0
|
||||||
|
}
|
||||||
|
|
||||||
startIdx, endIdx := self.GetSelectionRange()
|
startIdx, endIdx := self.GetSelectionRange()
|
||||||
|
|
||||||
nodes := []*FileNode{}
|
nodes := []*FileNode{}
|
||||||
|
Reference in New Issue
Block a user