mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
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.
This commit is contained in:
@ -259,7 +259,7 @@ func (gui *Gui) resetHelpersAndControllers() {
|
|||||||
gui.State.Contexts.Stash,
|
gui.State.Contexts.Stash,
|
||||||
} {
|
} {
|
||||||
controllers.AttachControllers(context, controllers.NewSwitchToDiffFilesController(
|
controllers.AttachControllers(context, controllers.NewSwitchToDiffFilesController(
|
||||||
common, context, gui.State.Contexts.CommitFiles,
|
common, context,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,15 +19,13 @@ type CanSwitchToDiffFiles interface {
|
|||||||
type SwitchToDiffFilesController struct {
|
type SwitchToDiffFilesController struct {
|
||||||
baseController
|
baseController
|
||||||
*ListControllerTrait[types.Ref]
|
*ListControllerTrait[types.Ref]
|
||||||
c *ControllerCommon
|
c *ControllerCommon
|
||||||
context CanSwitchToDiffFiles
|
context CanSwitchToDiffFiles
|
||||||
diffFilesContext *context.CommitFilesContext
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSwitchToDiffFilesController(
|
func NewSwitchToDiffFilesController(
|
||||||
c *ControllerCommon,
|
c *ControllerCommon,
|
||||||
context CanSwitchToDiffFiles,
|
context CanSwitchToDiffFiles,
|
||||||
diffFilesContext *context.CommitFilesContext,
|
|
||||||
) *SwitchToDiffFilesController {
|
) *SwitchToDiffFilesController {
|
||||||
return &SwitchToDiffFilesController{
|
return &SwitchToDiffFilesController{
|
||||||
baseController: baseController{},
|
baseController: baseController{},
|
||||||
@ -40,9 +37,8 @@ func NewSwitchToDiffFilesController(
|
|||||||
panic("Not implemented")
|
panic("Not implemented")
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
c: c,
|
c: c,
|
||||||
context: context,
|
context: context,
|
||||||
diffFilesContext: diffFilesContext,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,16 +68,16 @@ func (self *SwitchToDiffFilesController) enter(ref types.Ref) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesContextOpts) error {
|
func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesContextOpts) error {
|
||||||
diffFilesContext := self.diffFilesContext
|
commitFilesContext := self.c.Contexts().CommitFiles
|
||||||
|
|
||||||
diffFilesContext.SetSelection(0)
|
commitFilesContext.SetSelection(0)
|
||||||
diffFilesContext.SetRef(opts.Ref)
|
commitFilesContext.SetRef(opts.Ref)
|
||||||
diffFilesContext.SetTitleRef(opts.Ref.Description())
|
commitFilesContext.SetTitleRef(opts.Ref.Description())
|
||||||
diffFilesContext.SetCanRebase(opts.CanRebase)
|
commitFilesContext.SetCanRebase(opts.CanRebase)
|
||||||
diffFilesContext.SetParentContext(opts.Context)
|
commitFilesContext.SetParentContext(opts.Context)
|
||||||
diffFilesContext.SetWindowName(opts.Context.GetWindowName())
|
commitFilesContext.SetWindowName(opts.Context.GetWindowName())
|
||||||
diffFilesContext.ClearSearchString()
|
commitFilesContext.ClearSearchString()
|
||||||
diffFilesContext.GetView().TitlePrefix = opts.Context.GetView().TitlePrefix
|
commitFilesContext.GetView().TitlePrefix = opts.Context.GetView().TitlePrefix
|
||||||
|
|
||||||
if err := self.c.Refresh(types.RefreshOptions{
|
if err := self.c.Refresh(types.RefreshOptions{
|
||||||
Scope: []types.RefreshableView{types.COMMIT_FILES},
|
Scope: []types.RefreshableView{types.COMMIT_FILES},
|
||||||
@ -89,7 +85,7 @@ func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesConte
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.c.Context().Push(diffFilesContext)
|
return self.c.Context().Push(commitFilesContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *SwitchToDiffFilesController) itemRepresentsCommit(ref types.Ref) *types.DisabledReason {
|
func (self *SwitchToDiffFilesController) itemRepresentsCommit(ref types.Ref) *types.DisabledReason {
|
||||||
|
Reference in New Issue
Block a user