From 770d51634c26a58fb411dad1f69414f24cfe5962 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 25 Aug 2024 17:37:08 +0200 Subject: [PATCH] Cleanup: remove diffFilesContext field of SwitchToDiffFilesController I found this indirection confusing when reading the code. It looks like SwitchToDiffFilesController is instantiated with different such contexts, but it's always Contexts.CommitFiles, so just use that directly. --- pkg/gui/controllers.go | 2 +- .../switch_to_diff_files_controller.go | 32 ++++++++----------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/pkg/gui/controllers.go b/pkg/gui/controllers.go index d2f156a90..c784b4a1d 100644 --- a/pkg/gui/controllers.go +++ b/pkg/gui/controllers.go @@ -259,7 +259,7 @@ func (gui *Gui) resetHelpersAndControllers() { gui.State.Contexts.Stash, } { controllers.AttachControllers(context, controllers.NewSwitchToDiffFilesController( - common, context, gui.State.Contexts.CommitFiles, + common, context, )) } diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go index 92faefb79..4b7e9e930 100644 --- a/pkg/gui/controllers/switch_to_diff_files_controller.go +++ b/pkg/gui/controllers/switch_to_diff_files_controller.go @@ -1,7 +1,6 @@ package controllers import ( - "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -20,15 +19,13 @@ type CanSwitchToDiffFiles interface { type SwitchToDiffFilesController struct { baseController *ListControllerTrait[types.Ref] - c *ControllerCommon - context CanSwitchToDiffFiles - diffFilesContext *context.CommitFilesContext + c *ControllerCommon + context CanSwitchToDiffFiles } func NewSwitchToDiffFilesController( c *ControllerCommon, context CanSwitchToDiffFiles, - diffFilesContext *context.CommitFilesContext, ) *SwitchToDiffFilesController { return &SwitchToDiffFilesController{ baseController: baseController{}, @@ -40,9 +37,8 @@ func NewSwitchToDiffFilesController( panic("Not implemented") }, ), - c: c, - context: context, - diffFilesContext: diffFilesContext, + c: c, + context: context, } } @@ -72,16 +68,16 @@ func (self *SwitchToDiffFilesController) enter(ref types.Ref) error { } func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesContextOpts) error { - diffFilesContext := self.diffFilesContext + commitFilesContext := self.c.Contexts().CommitFiles - diffFilesContext.SetSelection(0) - diffFilesContext.SetRef(opts.Ref) - diffFilesContext.SetTitleRef(opts.Ref.Description()) - diffFilesContext.SetCanRebase(opts.CanRebase) - diffFilesContext.SetParentContext(opts.Context) - diffFilesContext.SetWindowName(opts.Context.GetWindowName()) - diffFilesContext.ClearSearchString() - diffFilesContext.GetView().TitlePrefix = opts.Context.GetView().TitlePrefix + commitFilesContext.SetSelection(0) + commitFilesContext.SetRef(opts.Ref) + commitFilesContext.SetTitleRef(opts.Ref.Description()) + commitFilesContext.SetCanRebase(opts.CanRebase) + commitFilesContext.SetParentContext(opts.Context) + commitFilesContext.SetWindowName(opts.Context.GetWindowName()) + commitFilesContext.ClearSearchString() + commitFilesContext.GetView().TitlePrefix = opts.Context.GetView().TitlePrefix if err := self.c.Refresh(types.RefreshOptions{ Scope: []types.RefreshableView{types.COMMIT_FILES}, @@ -89,7 +85,7 @@ func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesConte return err } - return self.c.Context().Push(diffFilesContext) + return self.c.Context().Push(commitFilesContext) } func (self *SwitchToDiffFilesController) itemRepresentsCommit(ref types.Ref) *types.DisabledReason {