mirror of
				https://github.com/jesseduffield/lazygit.git
				synced 2025-10-30 23:57:43 +02:00 
			
		
		
		
	Add IGuiCommon.GetViewBufferManagerForView
So that we don't have to pass the map to controllers.
This commit is contained in:
		| @@ -180,7 +180,7 @@ func (gui *Gui) resetHelpersAndControllers() { | ||||
| 	globalController := controllers.NewGlobalController(common) | ||||
| 	contextLinesController := controllers.NewContextLinesController(common) | ||||
| 	renameSimilarityThresholdController := controllers.NewRenameSimilarityThresholdController(common) | ||||
| 	verticalScrollControllerFactory := controllers.NewVerticalScrollControllerFactory(common, &gui.viewBufferManagerMap) | ||||
| 	verticalScrollControllerFactory := controllers.NewVerticalScrollControllerFactory(common) | ||||
|  | ||||
| 	branchesController := controllers.NewBranchesController(common) | ||||
| 	gitFlowController := controllers.NewGitFlowController(common) | ||||
|   | ||||
| @@ -3,29 +3,25 @@ package controllers | ||||
| import ( | ||||
| 	"github.com/jesseduffield/gocui" | ||||
| 	"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 | ||||
| // struct, but we're maintaining consistency with the other files. | ||||
| type VerticalScrollControllerFactory struct { | ||||
| 	c                    *ControllerCommon | ||||
| 	viewBufferManagerMap *map[string]*tasks.ViewBufferManager | ||||
| 	c *ControllerCommon | ||||
| } | ||||
|  | ||||
| func NewVerticalScrollControllerFactory(c *ControllerCommon, viewBufferManagerMap *map[string]*tasks.ViewBufferManager) *VerticalScrollControllerFactory { | ||||
| func NewVerticalScrollControllerFactory(c *ControllerCommon) *VerticalScrollControllerFactory { | ||||
| 	return &VerticalScrollControllerFactory{ | ||||
| 		c:                    c, | ||||
| 		viewBufferManagerMap: viewBufferManagerMap, | ||||
| 		c: c, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (self *VerticalScrollControllerFactory) Create(context types.Context) types.IController { | ||||
| 	return &VerticalScrollController{ | ||||
| 		baseController:       baseController{}, | ||||
| 		c:                    self.c, | ||||
| 		context:              context, | ||||
| 		viewBufferManagerMap: self.viewBufferManagerMap, | ||||
| 		baseController: baseController{}, | ||||
| 		c:              self.c, | ||||
| 		context:        context, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @@ -33,8 +29,7 @@ type VerticalScrollController struct { | ||||
| 	baseController | ||||
| 	c *ControllerCommon | ||||
|  | ||||
| 	context              types.Context | ||||
| 	viewBufferManagerMap *map[string]*tasks.ViewBufferManager | ||||
| 	context types.Context | ||||
| } | ||||
|  | ||||
| func (self *VerticalScrollController) Context() types.Context { | ||||
| @@ -74,7 +69,7 @@ func (self *VerticalScrollController) HandleScrollDown() error { | ||||
| 	scrollHeight := self.c.UserConfig().Gui.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) | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -20,7 +20,7 @@ func (gui *Gui) scrollDownView(view *gocui.View) { | ||||
| 	scrollHeight := gui.c.UserConfig().Gui.ScrollHeight | ||||
| 	view.ScrollDown(scrollHeight) | ||||
|  | ||||
| 	if manager, ok := gui.viewBufferManagerMap[view.Name()]; ok { | ||||
| 	if manager := gui.getViewBufferManagerForView(view); manager != nil { | ||||
| 		manager.ReadLines(scrollHeight) | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -578,6 +578,15 @@ func (gui *Gui) resetState(startArgs appTypes.StartArgs) types.Context { | ||||
| 	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] { | ||||
| 	result := utils.NewThreadSafeMap[string, string]() | ||||
|  | ||||
|   | ||||
| @@ -7,6 +7,7 @@ import ( | ||||
| 	"github.com/jesseduffield/lazygit/pkg/config" | ||||
| 	"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" | ||||
| 	"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 | ||||
| @@ -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 { | ||||
| 	return self.gui.stateAccessor | ||||
| } | ||||
|   | ||||
| @@ -32,10 +32,10 @@ func (gui *Gui) layout(g *gocui.Gui) error { | ||||
| 		newMainHeight := viewDimensions["main"].Y1 - viewDimensions["main"].Y0 + 1 | ||||
| 		heightDiff := newMainHeight - prevMainHeight | ||||
| 		if heightDiff > 0 { | ||||
| 			if manager, ok := gui.viewBufferManagerMap["main"]; ok { | ||||
| 			if manager := gui.getViewBufferManagerForView(gui.Views.Main); manager != nil { | ||||
| 				manager.ReadLines(heightDiff) | ||||
| 			} | ||||
| 			if manager, ok := gui.viewBufferManagerMap["secondary"]; ok { | ||||
| 			if manager := gui.getViewBufferManagerForView(gui.Views.Secondary); manager != nil { | ||||
| 				manager.ReadLines(heightDiff) | ||||
| 			} | ||||
| 		} | ||||
|   | ||||
| @@ -8,6 +8,7 @@ import ( | ||||
| 	"github.com/jesseduffield/lazygit/pkg/commands/oscommands" | ||||
| 	"github.com/jesseduffield/lazygit/pkg/common" | ||||
| 	"github.com/jesseduffield/lazygit/pkg/config" | ||||
| 	"github.com/jesseduffield/lazygit/pkg/tasks" | ||||
| 	"github.com/jesseduffield/lazygit/pkg/utils" | ||||
| 	"github.com/sasha-s/go-deadlock" | ||||
| 	"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 | ||||
| 	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 | ||||
| 	RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error) | ||||
| 	RunSubprocessAndRefresh(oscommands.ICmdObj) error | ||||
|   | ||||
		Reference in New Issue
	
	Block a user