From b93b8cc00a2f2ea339b1ecdbc380320556490d3b Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 6 Feb 2022 14:37:16 +1100 Subject: [PATCH] controller for viewing sub commits --- pkg/gui/commits_panel.go | 5 +- pkg/gui/context/branches_context.go | 9 ++ pkg/gui/context/list_context_trait.go | 5 - pkg/gui/context/local_commits_context.go | 14 ++- pkg/gui/context/remote_branches_context.go | 9 ++ pkg/gui/context/tags_context.go | 9 ++ .../controllers/local_commits_controller.go | 18 +-- pkg/gui/controllers/refs_helper.go | 33 +++--- pkg/gui/controllers/remotes_controller.go | 2 +- .../sub_commits_switch_controller.go | 105 ++++++++++++++++++ pkg/gui/controllers/tags_controller.go | 11 +- pkg/gui/filtering.go | 2 +- pkg/gui/gui.go | 32 +++--- pkg/gui/keybindings.go | 14 --- pkg/gui/menu_panel.go | 2 +- pkg/gui/reflog_panel.go | 2 +- pkg/gui/refresh.go | 2 +- pkg/gui/sub_commits_panel.go | 8 +- pkg/gui/types/context.go | 1 - pkg/gui/types/modes.go | 13 +++ 20 files changed, 210 insertions(+), 86 deletions(-) create mode 100644 pkg/gui/controllers/sub_commits_switch_controller.go create mode 100644 pkg/gui/types/modes.go diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 37e234e82..bed39a05a 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -15,8 +15,9 @@ func (gui *Gui) getSelectedLocalCommit() *models.Commit { } func (gui *Gui) onCommitFocus() error { - if gui.State.Contexts.BranchCommits.GetSelectedLineIdx() > COMMIT_THRESHOLD && gui.State.LimitCommits { - gui.State.LimitCommits = false + context := gui.State.Contexts.BranchCommits + if context.GetSelectedLineIdx() > COMMIT_THRESHOLD && context.GetLimitCommits() { + context.SetLimitCommits(false) go utils.Safe(func() { if err := gui.refreshCommitsWithLimit(); err != nil { _ = gui.c.Error(err) diff --git a/pkg/gui/context/branches_context.go b/pkg/gui/context/branches_context.go index 0be6e1dce..4b82844f4 100644 --- a/pkg/gui/context/branches_context.go +++ b/pkg/gui/context/branches_context.go @@ -84,3 +84,12 @@ func (self *BranchesViewModel) GetSelected() *models.Branch { return self.getModel()[self.GetSelectedLineIdx()] } + +func (self *BranchesViewModel) GetSelectedRefName() string { + item := self.GetSelected() + if item == nil { + return "" + } + + return item.RefName() +} diff --git a/pkg/gui/context/list_context_trait.go b/pkg/gui/context/list_context_trait.go index e4fab30bf..b716bb25e 100644 --- a/pkg/gui/context/list_context_trait.go +++ b/pkg/gui/context/list_context_trait.go @@ -20,11 +20,6 @@ func (self *ListContextTrait) GetList() types.IList { return self.list } -// TODO: remove -func (self *ListContextTrait) GetPanelState() types.IListPanelState { - return self.list -} - func (self *ListContextTrait) GetViewTrait() types.IViewTrait { return self.viewTrait } diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index 0345ecb81..533d97cb2 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -61,12 +61,14 @@ func (self *LocalCommitsContext) GetSelectedItemId() string { type LocalCommitsViewModel struct { *traits.ListCursor - getModel func() []*models.Commit + limitCommits bool + getModel func() []*models.Commit } func NewLocalCommitsViewModel(getModel func() []*models.Commit) *LocalCommitsViewModel { self := &LocalCommitsViewModel{ - getModel: getModel, + getModel: getModel, + limitCommits: true, } self.ListCursor = traits.NewListCursor(self) @@ -85,3 +87,11 @@ func (self *LocalCommitsViewModel) GetSelected() *models.Commit { return self.getModel()[self.GetSelectedLineIdx()] } + +func (self *LocalCommitsViewModel) SetLimitCommits(value bool) { + self.limitCommits = value +} + +func (self *LocalCommitsViewModel) GetLimitCommits() bool { + return self.limitCommits +} diff --git a/pkg/gui/context/remote_branches_context.go b/pkg/gui/context/remote_branches_context.go index e15e80261..6ec5f887b 100644 --- a/pkg/gui/context/remote_branches_context.go +++ b/pkg/gui/context/remote_branches_context.go @@ -84,3 +84,12 @@ func (self *RemoteBranchesViewModel) GetSelected() *models.RemoteBranch { return self.getModel()[self.GetSelectedLineIdx()] } + +func (self *RemoteBranchesViewModel) GetSelectedRefName() string { + item := self.GetSelected() + if item == nil { + return "" + } + + return item.RefName() +} diff --git a/pkg/gui/context/tags_context.go b/pkg/gui/context/tags_context.go index e0409cfba..169a4989d 100644 --- a/pkg/gui/context/tags_context.go +++ b/pkg/gui/context/tags_context.go @@ -84,3 +84,12 @@ func (self *TagsViewModel) GetSelected() *models.Tag { return self.getModel()[self.GetSelectedLineIdx()] } + +func (self *TagsViewModel) GetSelectedRefName() string { + item := self.GetSelected() + if item == nil { + return "" + } + + return item.RefName() +} diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 4ce7b88da..bb06a2314 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -38,8 +38,6 @@ type LocalCommitsController struct { pullFiles PullFilesFn getHostingServiceMgr GetHostingServiceMgrFn switchToCommitFilesContext SwitchToCommitFilesContextFn - getLimitCommits func() bool - setLimitCommits func(bool) getShowWholeGitGraph func() bool setShowWholeGitGraph func(bool) } @@ -60,8 +58,6 @@ func NewLocalCommitsController( pullFiles PullFilesFn, getHostingServiceMgr GetHostingServiceMgrFn, switchToCommitFilesContext SwitchToCommitFilesContextFn, - getLimitCommits func() bool, - setLimitCommits func(bool), getShowWholeGitGraph func() bool, setShowWholeGitGraph func(bool), ) *LocalCommitsController { @@ -80,8 +76,6 @@ func NewLocalCommitsController( pullFiles: pullFiles, getHostingServiceMgr: getHostingServiceMgr, switchToCommitFilesContext: switchToCommitFilesContext, - getLimitCommits: getLimitCommits, - setLimitCommits: setLimitCommits, getShowWholeGitGraph: getShowWholeGitGraph, setShowWholeGitGraph: setShowWholeGitGraph, } @@ -466,7 +460,7 @@ func (self *LocalCommitsController) handleCommitMoveDown() error { } func (self *LocalCommitsController) handleCommitMoveUp() error { - index := self.context.GetPanelState().GetSelectedLineIdx() + index := self.context.GetSelectedLineIdx() if index == 0 { return nil } @@ -641,8 +635,8 @@ func (self *LocalCommitsController) handleCreateCommitResetMenu(commit *models.C func (self *LocalCommitsController) openSearch() error { // we usually lazyload these commits but now that we're searching we need to load them now - if self.getLimitCommits() { - self.setLimitCommits(false) + if self.context.GetLimitCommits() { + self.context.SetLimitCommits(false) if err := self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.COMMITS}}); err != nil { return err } @@ -655,8 +649,8 @@ func (self *LocalCommitsController) openSearch() error { func (self *LocalCommitsController) gotoBottom() error { // we usually lazyload these commits but now that we're jumping to the bottom we need to load them now - if self.getLimitCommits() { - self.setLimitCommits(false) + if self.context.GetLimitCommits() { + self.context.SetLimitCommits(false) if err := self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.COMMITS}}); err != nil { return err } @@ -693,7 +687,7 @@ func (self *LocalCommitsController) handleOpenLogMenu() error { self.setShowWholeGitGraph(!self.getShowWholeGitGraph()) if self.getShowWholeGitGraph() { - self.setLimitCommits(false) + self.context.SetLimitCommits(false) } return self.c.WithWaitingStatus(self.c.Tr.LcLoadingCommits, func() error { diff --git a/pkg/gui/controllers/refs_helper.go b/pkg/gui/controllers/refs_helper.go index 8d56ec0d7..e6d9babfb 100644 --- a/pkg/gui/controllers/refs_helper.go +++ b/pkg/gui/controllers/refs_helper.go @@ -20,23 +20,20 @@ type IRefsHelper interface { } type RefsHelper struct { - c *types.ControllerCommon - git *commands.GitCommand - contexts *context.ContextTree - limitCommits func() + c *types.ControllerCommon + git *commands.GitCommand + contexts *context.ContextTree } func NewRefsHelper( c *types.ControllerCommon, git *commands.GitCommand, contexts *context.ContextTree, - limitCommits func(), ) *RefsHelper { return &RefsHelper{ - c: c, - git: git, - contexts: contexts, - limitCommits: limitCommits, + c: c, + git: git, + contexts: contexts, } } @@ -51,11 +48,11 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions cmdOptions := git_commands.CheckoutOptions{Force: false, EnvVars: options.EnvVars} onSuccess := func() { - self.contexts.Branches.GetPanelState().SetSelectedLineIdx(0) - self.contexts.BranchCommits.GetPanelState().SetSelectedLineIdx(0) - self.contexts.ReflogCommits.GetPanelState().SetSelectedLineIdx(0) + self.contexts.Branches.SetSelectedLineIdx(0) + self.contexts.ReflogCommits.SetSelectedLineIdx(0) + self.contexts.BranchCommits.SetSelectedLineIdx(0) // loading a heap of commits is slow so we limit them whenever doing a reset - self.limitCommits() + self.contexts.BranchCommits.SetLimitCommits(true) } return self.c.WithWaitingStatus(waitingStatus, func() error { @@ -107,10 +104,10 @@ func (self *RefsHelper) ResetToRef(ref string, strength string, envVars []string return self.c.Error(err) } - self.contexts.BranchCommits.GetPanelState().SetSelectedLineIdx(0) - self.contexts.ReflogCommits.GetPanelState().SetSelectedLineIdx(0) + self.contexts.BranchCommits.SetSelectedLineIdx(0) + self.contexts.ReflogCommits.SetSelectedLineIdx(0) // loading a heap of commits is slow so we limit them whenever doing a reset - self.limitCommits() + self.contexts.BranchCommits.SetLimitCommits(true) if err := self.c.PushContext(self.contexts.BranchCommits); err != nil { return err @@ -169,8 +166,8 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest } } - self.contexts.BranchCommits.GetPanelState().SetSelectedLineIdx(0) - self.contexts.Branches.GetPanelState().SetSelectedLineIdx(0) + self.contexts.BranchCommits.SetSelectedLineIdx(0) + self.contexts.Branches.SetSelectedLineIdx(0) return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}) }, diff --git a/pkg/gui/controllers/remotes_controller.go b/pkg/gui/controllers/remotes_controller.go index ff3b943fb..12d2e7459 100644 --- a/pkg/gui/controllers/remotes_controller.go +++ b/pkg/gui/controllers/remotes_controller.go @@ -81,7 +81,7 @@ func (self *RemotesController) enter(remote *models.Remote) error { if len(remote.Branches) == 0 { newSelectedLine = -1 } - self.contexts.RemoteBranches.GetPanelState().SetSelectedLineIdx(newSelectedLine) + self.contexts.RemoteBranches.SetSelectedLineIdx(newSelectedLine) return self.c.PushContext(self.contexts.RemoteBranches) } diff --git a/pkg/gui/controllers/sub_commits_switch_controller.go b/pkg/gui/controllers/sub_commits_switch_controller.go new file mode 100644 index 000000000..dbd6ab135 --- /dev/null +++ b/pkg/gui/controllers/sub_commits_switch_controller.go @@ -0,0 +1,105 @@ +package controllers + +import ( + "github.com/jesseduffield/lazygit/pkg/commands" + "github.com/jesseduffield/lazygit/pkg/commands/loaders" + "github.com/jesseduffield/lazygit/pkg/commands/models" + "github.com/jesseduffield/lazygit/pkg/gui/context" + "github.com/jesseduffield/lazygit/pkg/gui/types" +) + +type SubCommitsSwitchControllerFactory struct { + c *types.ControllerCommon + subCommitsContext *context.SubCommitsContext + git *commands.GitCommand + modes *types.Modes + setSubCommits func([]*models.Commit) +} + +var _ types.IController = &SubCommitsSwitchController{} + +type ContextWithRefName interface { + types.Context + GetSelectedRefName() string +} + +type SubCommitsSwitchController struct { + baseController + + c *types.ControllerCommon + context ContextWithRefName + subCommitsContext *context.SubCommitsContext + git *commands.GitCommand + modes *types.Modes + setSubCommits func([]*models.Commit) +} + +func NewSubCommitsSwitchControllerFactory( + c *types.ControllerCommon, + subCommitsContext *context.SubCommitsContext, + git *commands.GitCommand, + modes *types.Modes, + setSubCommits func([]*models.Commit), +) *SubCommitsSwitchControllerFactory { + return &SubCommitsSwitchControllerFactory{ + c: c, + subCommitsContext: subCommitsContext, + git: git, + modes: modes, + setSubCommits: setSubCommits, + } +} + +func (self *SubCommitsSwitchControllerFactory) Create(context ContextWithRefName) *SubCommitsSwitchController { + return &SubCommitsSwitchController{ + baseController: baseController{}, + c: self.c, + context: context, + subCommitsContext: self.subCommitsContext, + git: self.git, + modes: self.modes, + setSubCommits: self.setSubCommits, + } +} + +func (self *SubCommitsSwitchController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { + bindings := []*types.Binding{ + { + Handler: self.viewCommits, + Key: opts.GetKey(opts.Config.Universal.GoInto), + Description: self.c.Tr.LcViewCommits, + }, + } + + return bindings +} + +func (self *SubCommitsSwitchController) viewCommits() error { + refName := self.context.GetSelectedRefName() + if refName == "" { + return nil + } + + // need to populate my sub commits + commits, err := self.git.Loaders.Commits.GetCommits( + loaders.GetCommitsOptions{ + Limit: true, + FilterPath: self.modes.Filtering.GetPath(), + IncludeRebaseCommits: false, + RefName: refName, + }, + ) + if err != nil { + return err + } + + self.setSubCommits(commits) + self.subCommitsContext.SetSelectedLineIdx(0) + self.subCommitsContext.SetParentContext(self.context) + + return self.c.PushContext(self.subCommitsContext) +} + +func (self *SubCommitsSwitchController) Context() types.Context { + return self.context +} diff --git a/pkg/gui/controllers/tags_controller.go b/pkg/gui/controllers/tags_controller.go index 18135db02..e819c1973 100644 --- a/pkg/gui/controllers/tags_controller.go +++ b/pkg/gui/controllers/tags_controller.go @@ -78,11 +78,6 @@ func (self *TagsController) GetKeybindings(opts types.KeybindingsOpts) []*types. Description: self.c.Tr.LcViewResetOptions, OpensMenu: true, }, - { - Key: opts.GetKey(opts.Config.Universal.GoInto), - Handler: self.withSelectedTag(self.enter), - Description: self.c.Tr.LcViewCommits, - }, } return bindings @@ -96,10 +91,6 @@ func (self *TagsController) checkout(tag *models.Tag) error { return self.c.PushContext(self.contexts.Branches) } -func (self *TagsController) enter(tag *models.Tag) error { - return self.switchToSubCommitsContext(tag.Name) -} - func (self *TagsController) delete(tag *models.Tag) error { prompt := utils.ResolvePlaceholderString( self.c.Tr.DeleteTagPrompt, @@ -153,7 +144,7 @@ func (self *TagsController) createResetMenu(tag *models.Tag) error { func (self *TagsController) create() error { // leaving commit SHA blank so that we're just creating the tag for the current commit - return self.tagsHelper.CreateTagMenu("", func() { self.context.GetPanelState().SetSelectedLineIdx(0) }) + return self.tagsHelper.CreateTagMenu("", func() { self.context.SetSelectedLineIdx(0) }) } func (self *TagsController) withSelectedTag(f func(tag *models.Tag) error) func() error { diff --git a/pkg/gui/filtering.go b/pkg/gui/filtering.go index 6d75b2e77..4780387c9 100644 --- a/pkg/gui/filtering.go +++ b/pkg/gui/filtering.go @@ -51,6 +51,6 @@ func (gui *Gui) setFiltering(path string) error { } return gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}, Then: func() { - gui.State.Contexts.BranchCommits.GetPanelState().SetSelectedLineIdx(0) + gui.State.Contexts.BranchCommits.SetSelectedLineIdx(0) }}) } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 9038fe647..93e5c5ff3 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -175,7 +175,7 @@ type PrevLayout struct { type GuiRepoState struct { Model *types.Model - Modes Modes + Modes *types.Modes // Suggestions will sometimes appear when typing into a prompt Suggestions []*types.Suggestion @@ -297,12 +297,6 @@ const ( COMPLETE ) -type Modes struct { - Filtering filtering.Filtering - CherryPicking *cherrypicking.CherryPicking - Diffing diffing.Diffing -} - // if you add a new mutex here be sure to instantiate it. We're using pointers to // mutexes so that we can pass the mutexes to controllers. type guiMutexes struct { @@ -397,9 +391,8 @@ func (gui *Gui) resetState(filterPath string, reuseState bool) { UserVerticalScrolling: false, }, }, - LimitCommits: true, - Ptmx: nil, - Modes: Modes{ + Ptmx: nil, + Modes: &types.Modes{ Filtering: filtering.New(filterPath), CherryPicking: cherrypicking.New(), Diffing: diffing.New(), @@ -517,7 +510,6 @@ func (gui *Gui) resetControllers() { controllerCommon, gui.git, gui.State.Contexts, - func() { gui.State.LimitCommits = true }, ), Bisect: controllers.NewBisectHelper(controllerCommon, gui.git), Suggestions: controllers.NewSuggestionsHelper(controllerCommon, model, gui.refreshSuggestions), @@ -608,8 +600,6 @@ func (gui *Gui) resetControllers() { syncController.HandlePull, gui.getHostingServiceMgr, gui.SwitchToCommitFilesContext, - func() bool { return gui.State.LimitCommits }, - func(value bool) { gui.State.LimitCommits = value }, func() bool { return gui.ShowWholeGitGraph }, func(value bool) { gui.ShowWholeGitGraph = value }, ), @@ -634,6 +624,22 @@ func (gui *Gui) resetControllers() { Sync: syncController, } + switchToSubCommitsControllerFactory := controllers.NewSubCommitsSwitchControllerFactory( + controllerCommon, + gui.State.Contexts.SubCommits, + gui.git, + gui.State.Modes, + func(commits []*models.Commit) { gui.State.Model.SubCommits = commits }, + ) + + for _, context := range []controllers.ContextWithRefName{ + gui.State.Contexts.Branches, + gui.State.Contexts.RemoteBranches, + gui.State.Contexts.Tags, + } { + controllers.AttachControllers(context, switchToSubCommitsControllerFactory.Create(context)) + } + controllers.AttachControllers(gui.State.Contexts.Files, gui.Controllers.Files) controllers.AttachControllers(gui.State.Contexts.Tags, gui.Controllers.Tags) controllers.AttachControllers(gui.State.Contexts.Submodules, gui.Controllers.Submodules) diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 0083cd940..4b66281fc 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -477,13 +477,6 @@ func (gui *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBin Handler: gui.handleCopySelectedSideContextItemToClipboard, Description: gui.c.Tr.LcCopyBranchNameToClipboard, }, - { - ViewName: "branches", - Contexts: []string{string(context.LOCAL_BRANCHES_CONTEXT_KEY)}, - Key: gui.getKey(config.Universal.GoInto), - Handler: gui.handleEnterBranch, - Description: gui.c.Tr.LcViewCommits, - }, { ViewName: "branches", Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)}, @@ -499,13 +492,6 @@ func (gui *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBin Description: gui.c.Tr.LcViewResetOptions, OpensMenu: true, }, - { - ViewName: "branches", - Contexts: []string{string(context.REMOTE_BRANCHES_CONTEXT_KEY)}, - Key: gui.getKey(config.Universal.GoInto), - Handler: gui.handleEnterRemoteBranch, - Description: gui.c.Tr.LcViewCommits, - }, { ViewName: "commits", Contexts: []string{string(context.BRANCH_COMMITS_CONTEXT_KEY)}, diff --git a/pkg/gui/menu_panel.go b/pkg/gui/menu_panel.go index 9388be279..4afe931d1 100644 --- a/pkg/gui/menu_panel.go +++ b/pkg/gui/menu_panel.go @@ -49,7 +49,7 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error { })) gui.State.Contexts.Menu.SetMenuItems(opts.Items) - gui.State.Contexts.Menu.GetPanelState().SetSelectedLineIdx(0) + gui.State.Contexts.Menu.SetSelectedLineIdx(0) _ = gui.c.PostRefreshUpdate(gui.State.Contexts.Menu) // TODO: ensure that if we're opened a menu from within a menu that it renders correctly diff --git a/pkg/gui/reflog_panel.go b/pkg/gui/reflog_panel.go index 57b4e0a35..472c073cd 100644 --- a/pkg/gui/reflog_panel.go +++ b/pkg/gui/reflog_panel.go @@ -88,5 +88,5 @@ func (gui *Gui) handleCopyReflogCommitRange() error { return nil } - return gui.helpers.CherryPick.CopyRange(gui.State.Contexts.ReflogCommits.GetPanelState().GetSelectedLineIdx(), gui.State.Model.FilteredReflogCommits, gui.State.Contexts.ReflogCommits) + return gui.helpers.CherryPick.CopyRange(gui.State.Contexts.ReflogCommits.GetSelectedLineIdx(), gui.State.Model.FilteredReflogCommits, gui.State.Contexts.ReflogCommits) } diff --git a/pkg/gui/refresh.go b/pkg/gui/refresh.go index d4ed2d2f9..84d58d815 100644 --- a/pkg/gui/refresh.go +++ b/pkg/gui/refresh.go @@ -211,7 +211,7 @@ func (gui *Gui) refreshCommitsWithLimit() error { commits, err := gui.git.Loaders.Commits.GetCommits( loaders.GetCommitsOptions{ - Limit: gui.State.LimitCommits, + Limit: gui.State.Contexts.BranchCommits.GetLimitCommits(), FilterPath: gui.State.Modes.Filtering.GetPath(), IncludeRebaseCommits: true, RefName: gui.refForLog(), diff --git a/pkg/gui/sub_commits_panel.go b/pkg/gui/sub_commits_panel.go index 04c131625..ddcb8f096 100644 --- a/pkg/gui/sub_commits_panel.go +++ b/pkg/gui/sub_commits_panel.go @@ -45,7 +45,7 @@ func (gui *Gui) handleCheckoutSubCommit() error { return err } - gui.State.Contexts.SubCommits.GetPanelState().SetSelectedLineIdx(0) + gui.State.Contexts.SubCommits.SetSelectedLineIdx(0) return nil } @@ -74,7 +74,7 @@ func (gui *Gui) switchToSubCommitsContext(refName string) error { // need to populate my sub commits commits, err := gui.git.Loaders.Commits.GetCommits( loaders.GetCommitsOptions{ - Limit: gui.State.LimitCommits, + Limit: true, FilterPath: gui.State.Modes.Filtering.GetPath(), IncludeRebaseCommits: false, RefName: refName, @@ -85,7 +85,7 @@ func (gui *Gui) switchToSubCommitsContext(refName string) error { } gui.State.Model.SubCommits = commits - gui.State.Contexts.SubCommits.GetPanelState().SetSelectedLineIdx(0) + gui.State.Contexts.SubCommits.SetSelectedLineIdx(0) gui.State.Contexts.SubCommits.SetParentContext(gui.currentSideListContext()) return gui.c.PushContext(gui.State.Contexts.SubCommits) @@ -116,5 +116,5 @@ func (gui *Gui) handleCopySubCommitRange() error { return nil } - return gui.helpers.CherryPick.CopyRange(gui.State.Contexts.SubCommits.GetPanelState().GetSelectedLineIdx(), gui.State.Model.SubCommits, gui.State.Contexts.SubCommits) + return gui.helpers.CherryPick.CopyRange(gui.State.Contexts.SubCommits.GetSelectedLineIdx(), gui.State.Model.SubCommits, gui.State.Contexts.SubCommits) } diff --git a/pkg/gui/types/context.go b/pkg/gui/types/context.go index 2f59b15f5..ed971d348 100644 --- a/pkg/gui/types/context.go +++ b/pkg/gui/types/context.go @@ -59,7 +59,6 @@ type IListContext interface { OnSearchSelect(selectedLineIdx int) error FocusLine() - GetPanelState() IListPanelState GetViewTrait() IViewTrait } diff --git a/pkg/gui/types/modes.go b/pkg/gui/types/modes.go new file mode 100644 index 000000000..ba135de63 --- /dev/null +++ b/pkg/gui/types/modes.go @@ -0,0 +1,13 @@ +package types + +import ( + "github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking" + "github.com/jesseduffield/lazygit/pkg/gui/modes/diffing" + "github.com/jesseduffield/lazygit/pkg/gui/modes/filtering" +) + +type Modes struct { + Filtering filtering.Filtering + CherryPicking *cherrypicking.CherryPicking + Diffing diffing.Diffing +}