diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-19 09:05:43 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-23 14:29:18 +1000 |
commit | 2fdadd383a2609921abd4aeb99e67bd5f1bbc0fc (patch) | |
tree | f52567d882bcf505ef05bfe9efed51eee28157ac /pkg/gui/branches_panel.go | |
parent | 9a2dc3fe150a03ccb4f086b05d8a8249c9e6c37f (diff) |
introduce new approach to handling tab states
Diffstat (limited to 'pkg/gui/branches_panel.go')
-rw-r--r-- | pkg/gui/branches_panel.go | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 926c589f0..4efbe6397 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -446,30 +446,24 @@ func (gui *Gui) handleFastForward(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) onBranchesTabClick(tabIndex int) error { - contexts := []string{"local-branches", "remotes", "tags"} branchesView := gui.getBranchesView() branchesView.TabIndex = tabIndex - return gui.switchBranchesPanelContext(contexts[tabIndex]) -} + context := gui.ViewTabContextMap["branches"][tabIndex].contexts[0] -func (gui *Gui) switchBranchesPanelContext(context string) error { - branchesView := gui.getBranchesView() - branchesView.Context = context - if err := gui.onSearchEscape(); err != nil { - return err - } + return gui.switchContext(context) +} - contextTabIndexMap := map[string]int{ - "local-branches": 0, - "remotes": 1, - "remote-branches": 1, - "tags": 2, +func (gui *Gui) tabIndexForContext(c Context, tabContexts tabContexts) int { + for i, tabContext := range tabContexts { + for _, context := range tabContext.contexts { + if context.GetKey() == c.GetKey() { + return i + } + } } - - branchesView.TabIndex = contextTabIndexMap[context] - - return gui.refreshBranchesViewWithSelection() + gui.Log.Errorf("tab not found for context %s", c.GetKey()) + return 0 } func (gui *Gui) refreshBranchesViewWithSelection() error { |