diff options
-rw-r--r-- | pkg/gui/filetree/file_tree.go | 4 | ||||
-rw-r--r-- | pkg/gui/filetree/file_tree_view_model.go | 4 |
2 files changed, 7 insertions, 1 deletions
diff --git a/pkg/gui/filetree/file_tree.go b/pkg/gui/filetree/file_tree.go index 9d3bb580d..b80499cfd 100644 --- a/pkg/gui/filetree/file_tree.go +++ b/pkg/gui/filetree/file_tree.go @@ -5,6 +5,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/types" + "github.com/jesseduffield/lazygit/pkg/utils" "github.com/samber/lo" "github.com/sirupsen/logrus" ) @@ -138,7 +139,8 @@ func (self *FileTree) GetAllItems() []*FileNode { } 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 { diff --git a/pkg/gui/filetree/file_tree_view_model.go b/pkg/gui/filetree/file_tree_view_model.go index 05cc9cb89..439471b01 100644 --- a/pkg/gui/filetree/file_tree_view_model.go +++ b/pkg/gui/filetree/file_tree_view_model.go @@ -54,6 +54,10 @@ func (self *FileTreeViewModel) GetSelectedItemId() string { } func (self *FileTreeViewModel) GetSelectedItems() ([]*FileNode, int, int) { + if self.Len() == 0 { + return nil, 0, 0 + } + startIdx, endIdx := self.GetSelectionRange() nodes := []*FileNode{} |