mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-29 22:48:24 +02:00
Set groundwork for better disabled reasons with range select
Something dumb that we're currently doing is expecting list items to define an ID method which returns a string. We use that when copying items to clipboard with ctrl+o and when getting a ref name for diffing. This commit gets us a little deeper into that hole by explicitly requiring list items to implement that method so that we can easily use the new helper functions in list_controller_trait.go. In future we need to just remove the whole ID thing entirely but I'm too lazy to do that right now.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context/traits"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
"github.com/samber/lo"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -43,6 +44,36 @@ func (self *FileTreeViewModel) GetSelected() *FileNode {
|
||||
return self.Get(self.GetSelectedLineIdx())
|
||||
}
|
||||
|
||||
func (self *FileTreeViewModel) GetSelectedItemId() string {
|
||||
item := self.GetSelected()
|
||||
if item == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return item.ID()
|
||||
}
|
||||
|
||||
func (self *FileTreeViewModel) GetSelectedItems() ([]*FileNode, int, int) {
|
||||
startIdx, endIdx := self.GetSelectionRange()
|
||||
|
||||
nodes := []*FileNode{}
|
||||
for i := startIdx; i <= endIdx; i++ {
|
||||
nodes = append(nodes, self.Get(i))
|
||||
}
|
||||
|
||||
return nodes, startIdx, endIdx
|
||||
}
|
||||
|
||||
func (self *FileTreeViewModel) GetSelectedItemIds() ([]string, int, int) {
|
||||
selectedItems, startIdx, endIdx := self.GetSelectedItems()
|
||||
|
||||
ids := lo.Map(selectedItems, func(item *FileNode, _ int) string {
|
||||
return item.ID()
|
||||
})
|
||||
|
||||
return ids, startIdx, endIdx
|
||||
}
|
||||
|
||||
func (self *FileTreeViewModel) GetSelectedFile() *models.File {
|
||||
node := self.GetSelected()
|
||||
if node == nil {
|
||||
|
||||
Reference in New Issue
Block a user