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:
@ -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)
|
||||||
|
@ -3,29 +3,25 @@ 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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *VerticalScrollControllerFactory) Create(context types.Context) types.IController {
|
func (self *VerticalScrollControllerFactory) Create(context types.Context) types.IController {
|
||||||
return &VerticalScrollController{
|
return &VerticalScrollController{
|
||||||
baseController: baseController{},
|
baseController: baseController{},
|
||||||
c: self.c,
|
c: self.c,
|
||||||
context: context,
|
context: context,
|
||||||
viewBufferManagerMap: self.viewBufferManagerMap,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,8 +29,7 @@ type VerticalScrollController struct {
|
|||||||
baseController
|
baseController
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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]()
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Reference in New Issue
Block a user