1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

Add IGuiCommon.GetViewBufferManagerForView

So that we don't have to pass the map to controllers.
This commit is contained in:
Stefan Haller
2025-04-03 18:00:13 +02:00
parent b97dd6bc3f
commit 7b96615792
7 changed files with 30 additions and 17 deletions

View File

@ -180,7 +180,7 @@ func (gui *Gui) resetHelpersAndControllers() {
globalController := controllers.NewGlobalController(common) globalController := controllers.NewGlobalController(common)
contextLinesController := controllers.NewContextLinesController(common) contextLinesController := controllers.NewContextLinesController(common)
renameSimilarityThresholdController := controllers.NewRenameSimilarityThresholdController(common) renameSimilarityThresholdController := controllers.NewRenameSimilarityThresholdController(common)
verticalScrollControllerFactory := controllers.NewVerticalScrollControllerFactory(common, &gui.viewBufferManagerMap) verticalScrollControllerFactory := controllers.NewVerticalScrollControllerFactory(common)
branchesController := controllers.NewBranchesController(common) branchesController := controllers.NewBranchesController(common)
gitFlowController := controllers.NewGitFlowController(common) gitFlowController := controllers.NewGitFlowController(common)

View File

@ -3,20 +3,17 @@ package controllers
import ( import (
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/tasks"
) )
// given we have no fields here, arguably we shouldn't even need this factory // given we have no fields here, arguably we shouldn't even need this factory
// struct, but we're maintaining consistency with the other files. // struct, but we're maintaining consistency with the other files.
type VerticalScrollControllerFactory struct { type VerticalScrollControllerFactory struct {
c *ControllerCommon c *ControllerCommon
viewBufferManagerMap *map[string]*tasks.ViewBufferManager
} }
func NewVerticalScrollControllerFactory(c *ControllerCommon, viewBufferManagerMap *map[string]*tasks.ViewBufferManager) *VerticalScrollControllerFactory { func NewVerticalScrollControllerFactory(c *ControllerCommon) *VerticalScrollControllerFactory {
return &VerticalScrollControllerFactory{ return &VerticalScrollControllerFactory{
c: c, c: c,
viewBufferManagerMap: viewBufferManagerMap,
} }
} }
@ -25,7 +22,6 @@ func (self *VerticalScrollControllerFactory) Create(context types.Context) types
baseController: baseController{}, baseController: baseController{},
c: self.c, c: self.c,
context: context, context: context,
viewBufferManagerMap: self.viewBufferManagerMap,
} }
} }
@ -34,7 +30,6 @@ type VerticalScrollController struct {
c *ControllerCommon c *ControllerCommon
context types.Context context types.Context
viewBufferManagerMap *map[string]*tasks.ViewBufferManager
} }
func (self *VerticalScrollController) Context() types.Context { func (self *VerticalScrollController) Context() types.Context {
@ -74,7 +69,7 @@ func (self *VerticalScrollController) HandleScrollDown() error {
scrollHeight := self.c.UserConfig().Gui.ScrollHeight scrollHeight := self.c.UserConfig().Gui.ScrollHeight
self.context.GetViewTrait().ScrollDown(scrollHeight) self.context.GetViewTrait().ScrollDown(scrollHeight)
if manager, ok := (*self.viewBufferManagerMap)[self.context.GetViewName()]; ok { if manager := self.c.GetViewBufferManagerForView(self.context.GetView()); manager != nil {
manager.ReadLines(scrollHeight) manager.ReadLines(scrollHeight)
} }

View File

@ -20,7 +20,7 @@ func (gui *Gui) scrollDownView(view *gocui.View) {
scrollHeight := gui.c.UserConfig().Gui.ScrollHeight scrollHeight := gui.c.UserConfig().Gui.ScrollHeight
view.ScrollDown(scrollHeight) view.ScrollDown(scrollHeight)
if manager, ok := gui.viewBufferManagerMap[view.Name()]; ok { if manager := gui.getViewBufferManagerForView(view); manager != nil {
manager.ReadLines(scrollHeight) manager.ReadLines(scrollHeight)
} }
} }

View File

@ -578,6 +578,15 @@ func (gui *Gui) resetState(startArgs appTypes.StartArgs) types.Context {
return initialContext(contextTree, startArgs) return initialContext(contextTree, startArgs)
} }
func (self *Gui) getViewBufferManagerForView(view *gocui.View) *tasks.ViewBufferManager {
manager, ok := self.viewBufferManagerMap[view.Name()]
if !ok {
return nil
}
return manager
}
func initialWindowViewNameMap(contextTree *context.ContextTree) *utils.ThreadSafeMap[string, string] { func initialWindowViewNameMap(contextTree *context.ContextTree) *utils.ThreadSafeMap[string, string] {
result := utils.NewThreadSafeMap[string, string]() result := utils.NewThreadSafeMap[string, string]()

View File

@ -7,6 +7,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/tasks"
) )
// hacking this by including the gui struct for now until we split more things out // hacking this by including the gui struct for now until we split more things out
@ -128,6 +129,10 @@ func (self *guiCommon) MainViewPairs() types.MainViewPairs {
} }
} }
func (self *guiCommon) GetViewBufferManagerForView(view *gocui.View) *tasks.ViewBufferManager {
return self.gui.getViewBufferManagerForView(view)
}
func (self *guiCommon) State() types.IStateAccessor { func (self *guiCommon) State() types.IStateAccessor {
return self.gui.stateAccessor return self.gui.stateAccessor
} }

View File

@ -32,10 +32,10 @@ func (gui *Gui) layout(g *gocui.Gui) error {
newMainHeight := viewDimensions["main"].Y1 - viewDimensions["main"].Y0 + 1 newMainHeight := viewDimensions["main"].Y1 - viewDimensions["main"].Y0 + 1
heightDiff := newMainHeight - prevMainHeight heightDiff := newMainHeight - prevMainHeight
if heightDiff > 0 { if heightDiff > 0 {
if manager, ok := gui.viewBufferManagerMap["main"]; ok { if manager := gui.getViewBufferManagerForView(gui.Views.Main); manager != nil {
manager.ReadLines(heightDiff) manager.ReadLines(heightDiff)
} }
if manager, ok := gui.viewBufferManagerMap["secondary"]; ok { if manager := gui.getViewBufferManagerForView(gui.Views.Secondary); manager != nil {
manager.ReadLines(heightDiff) manager.ReadLines(heightDiff)
} }
} }

View File

@ -8,6 +8,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/common" "github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/tasks"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
"github.com/sasha-s/go-deadlock" "github.com/sasha-s/go-deadlock"
"gopkg.in/ozeidan/fuzzy-patricia.v3/patricia" "gopkg.in/ozeidan/fuzzy-patricia.v3/patricia"
@ -48,6 +49,9 @@ type IGuiCommon interface {
// used purely for the sake of RenderToMainViews to provide the pair of main views we want to render to // used purely for the sake of RenderToMainViews to provide the pair of main views we want to render to
MainViewPairs() MainViewPairs MainViewPairs() MainViewPairs
// return the view buffer manager for the given view, or nil if it doesn't have one
GetViewBufferManagerForView(view *gocui.View) *tasks.ViewBufferManager
// returns true if command completed successfully // returns true if command completed successfully
RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error) RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error)
RunSubprocessAndRefresh(oscommands.ICmdObj) error RunSubprocessAndRefresh(oscommands.ICmdObj) error