mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Pass common.Common to file trees instead of just the Log
We will need a user config in the file tree in the next commit, and passing the entire common is the easiest way to do that while ensuring hot-reloading when users change the config while lazygit is running.
This commit is contained in:
@ -29,7 +29,7 @@ var (
|
||||
func NewCommitFilesContext(c *ContextCommon) *CommitFilesContext {
|
||||
viewModel := filetree.NewCommitFileTreeViewModel(
|
||||
func() []*models.CommitFile { return c.Model().CommitFiles },
|
||||
c.Log,
|
||||
c.Common,
|
||||
c.UserConfig().Gui.ShowFileTree,
|
||||
)
|
||||
|
||||
|
@ -24,7 +24,7 @@ var (
|
||||
func NewWorkingTreeContext(c *ContextCommon) *WorkingTreeContext {
|
||||
viewModel := filetree.NewFileTreeViewModel(
|
||||
func() []*models.File { return c.Model().Files },
|
||||
c.Log,
|
||||
c.Common,
|
||||
c.UserConfig().Gui.ShowFileTree,
|
||||
)
|
||||
|
||||
|
@ -2,9 +2,9 @@ package filetree
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/samber/lo"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type ICommitFileTree interface {
|
||||
@ -21,7 +21,7 @@ type CommitFileTree struct {
|
||||
getFiles func() []*models.CommitFile
|
||||
tree *Node[models.CommitFile]
|
||||
showTree bool
|
||||
log *logrus.Entry
|
||||
common *common.Common
|
||||
collapsedPaths *CollapsedPaths
|
||||
}
|
||||
|
||||
@ -41,10 +41,10 @@ func (self *CommitFileTree) ExpandAll() {
|
||||
|
||||
var _ ICommitFileTree = &CommitFileTree{}
|
||||
|
||||
func NewCommitFileTree(getFiles func() []*models.CommitFile, log *logrus.Entry, showTree bool) *CommitFileTree {
|
||||
func NewCommitFileTree(getFiles func() []*models.CommitFile, common *common.Common, showTree bool) *CommitFileTree {
|
||||
return &CommitFileTree{
|
||||
getFiles: getFiles,
|
||||
log: log,
|
||||
common: common,
|
||||
showTree: showTree,
|
||||
collapsedPaths: NewCollapsedPaths(),
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context/traits"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/samber/lo"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type ICommitFileTreeViewModel interface {
|
||||
@ -43,8 +43,8 @@ type CommitFileTreeViewModel struct {
|
||||
|
||||
var _ ICommitFileTreeViewModel = &CommitFileTreeViewModel{}
|
||||
|
||||
func NewCommitFileTreeViewModel(getFiles func() []*models.CommitFile, log *logrus.Entry, showTree bool) *CommitFileTreeViewModel {
|
||||
fileTree := NewCommitFileTree(getFiles, log, showTree)
|
||||
func NewCommitFileTreeViewModel(getFiles func() []*models.CommitFile, common *common.Common, showTree bool) *CommitFileTreeViewModel {
|
||||
fileTree := NewCommitFileTree(getFiles, common, showTree)
|
||||
listCursor := traits.NewListCursor(fileTree.Len)
|
||||
return &CommitFileTreeViewModel{
|
||||
ICommitFileTree: fileTree,
|
||||
|
@ -4,9 +4,9 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/samber/lo"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type FileTreeDisplayFilter int
|
||||
@ -54,17 +54,17 @@ type FileTree struct {
|
||||
getFiles func() []*models.File
|
||||
tree *Node[models.File]
|
||||
showTree bool
|
||||
log *logrus.Entry
|
||||
common *common.Common
|
||||
filter FileTreeDisplayFilter
|
||||
collapsedPaths *CollapsedPaths
|
||||
}
|
||||
|
||||
var _ IFileTree = &FileTree{}
|
||||
|
||||
func NewFileTree(getFiles func() []*models.File, log *logrus.Entry, showTree bool) *FileTree {
|
||||
func NewFileTree(getFiles func() []*models.File, common *common.Common, showTree bool) *FileTree {
|
||||
return &FileTree{
|
||||
getFiles: getFiles,
|
||||
log: log,
|
||||
common: common,
|
||||
showTree: showTree,
|
||||
filter: DisplayAll,
|
||||
collapsedPaths: NewCollapsedPaths(),
|
||||
|
@ -5,11 +5,11 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
"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"
|
||||
)
|
||||
|
||||
type IFileTreeViewModel interface {
|
||||
@ -28,8 +28,8 @@ type FileTreeViewModel struct {
|
||||
|
||||
var _ IFileTreeViewModel = &FileTreeViewModel{}
|
||||
|
||||
func NewFileTreeViewModel(getFiles func() []*models.File, log *logrus.Entry, showTree bool) *FileTreeViewModel {
|
||||
fileTree := NewFileTree(getFiles, log, showTree)
|
||||
func NewFileTreeViewModel(getFiles func() []*models.File, common *common.Common, showTree bool) *FileTreeViewModel {
|
||||
fileTree := NewFileTree(getFiles, common, showTree)
|
||||
listCursor := traits.NewListCursor(fileTree.Len)
|
||||
return &FileTreeViewModel{
|
||||
IFileTree: fileTree,
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"github.com/gookit/color"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/patch"
|
||||
"github.com/jesseduffield/lazygit/pkg/common"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
@ -87,7 +88,8 @@ func TestRenderFileTree(t *testing.T) {
|
||||
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
viewModel := filetree.NewFileTree(func() []*models.File { return s.files }, utils.NewDummyLog(), true)
|
||||
common := common.NewDummyCommon()
|
||||
viewModel := filetree.NewFileTree(func() []*models.File { return s.files }, common, true)
|
||||
viewModel.SetTree()
|
||||
for _, path := range s.collapsedPaths {
|
||||
viewModel.ToggleCollapsed(path)
|
||||
@ -151,7 +153,8 @@ func TestRenderCommitFileTree(t *testing.T) {
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
hashPool := &utils.StringPool{}
|
||||
|
||||
viewModel := filetree.NewCommitFileTreeViewModel(func() []*models.CommitFile { return s.files }, utils.NewDummyLog(), true)
|
||||
common := common.NewDummyCommon()
|
||||
viewModel := filetree.NewCommitFileTreeViewModel(func() []*models.CommitFile { return s.files }, common, true)
|
||||
viewModel.SetRef(models.NewCommit(hashPool, models.NewCommitOpts{Hash: "1234"}))
|
||||
viewModel.SetTree()
|
||||
for _, path := range s.collapsedPaths {
|
||||
|
Reference in New Issue
Block a user