diff options
Diffstat (limited to 'pkg/gui/view_helpers.go')
-rw-r--r-- | pkg/gui/view_helpers.go | 78 |
1 files changed, 49 insertions, 29 deletions
diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 023a1b41c..775a024df 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/jesseduffield/gocui" + "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" "github.com/spkg/bom" ) @@ -116,52 +117,71 @@ func (gui *Gui) popupPanelFocused() bool { return gui.isPopupPanel(gui.currentViewName()) } -// secondaryViewFocused tells us whether it appears that the secondary view is focused. The view is actually never focused for real: we just swap the main and secondary views and then you're still focused on the main view so that we can give you access to all its keybindings for free. I will probably regret this design decision soon enough. -func (gui *Gui) secondaryViewFocused() bool { - state := gui.State.Panels.LineByLine - return state != nil && state.SecondaryFocused -} +func (gui *Gui) onViewTabClick(windowName string, tabIndex int) error { + tabs := gui.viewTabMap()[windowName] + if len(tabs) == 0 { + return nil + } -func (gui *Gui) onViewTabClick(viewName string, tabIndex int) error { - context := gui.State.ViewTabContextMap[viewName][tabIndex].Context + viewName := tabs[tabIndex].ViewName + + context, ok := gui.contextForView(viewName) + if !ok { + return nil + } return gui.c.PushContext(context) } -func (gui *Gui) handleNextTab() error { - v := getTabbedView(gui) - if v == nil { - return nil +func (gui *Gui) contextForView(viewName string) (types.Context, bool) { + view, err := gui.g.View(viewName) + if err != nil { + return nil, false + } + + for _, context := range gui.State.Contexts.Flatten() { + if context.GetViewName() == view.Name() { + return context, true + } } - return gui.onViewTabClick( - v.Name(), - utils.ModuloWithWrap(v.TabIndex+1, len(v.Tabs)), - ) + return nil, false } -func (gui *Gui) handlePrevTab() error { - v := getTabbedView(gui) - if v == nil { +func (gui *Gui) handleNextTab() error { + view := getTabbedView(gui) + if view == nil { return nil } - return gui.onViewTabClick( - v.Name(), - utils.ModuloWithWrap(v.TabIndex-1, len(v.Tabs)), - ) + for _, context := range gui.State.Contexts.Flatten() { + if context.GetViewName() == view.Name() { + return gui.onViewTabClick( + context.GetWindowName(), + utils.ModuloWithWrap(view.TabIndex+1, len(view.Tabs)), + ) + } + } + + return nil } -// this is the distance we will move the cursor when paging up or down in a view -func (gui *Gui) pageDelta(view *gocui.View) int { - _, height := view.Size() +func (gui *Gui) handlePrevTab() error { + view := getTabbedView(gui) + if view == nil { + return nil + } - delta := height - 1 - if delta == 0 { - return 1 + for _, context := range gui.State.Contexts.Flatten() { + if context.GetViewName() == view.Name() { + return gui.onViewTabClick( + context.GetWindowName(), + utils.ModuloWithWrap(view.TabIndex-1, len(view.Tabs)), + ) + } } - return delta + return nil } func getTabbedView(gui *Gui) *gocui.View { |