diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-16 16:20:05 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-21 22:07:14 +1100 |
commit | 92e43d9e7776cd2e1796bf280756c6ffa7c8dbe2 (patch) | |
tree | ac3b7ee152e6b8cde6268d8c329334041cfe0d97 | |
parent | 325408d0e3db8e1b7d0b6915986f1a684ee8b257 (diff) |
allow changing tabs with [ and ]
-rw-r--r-- | pkg/gui/branches_panel.go | 12 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 12 | ||||
-rw-r--r-- | pkg/utils/utils.go | 11 |
3 files changed, 35 insertions, 0 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 015f51739..a05d3ed2a 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -372,3 +372,15 @@ func (gui *Gui) refreshRemotes() error { return nil } + +func (gui *Gui) handleNextBranchesTab(g *gocui.Gui, v *gocui.View) error { + return gui.onBranchesTabClick( + utils.ModuloWithWrap(v.TabIndex+1, len(v.Tabs)), + ) +} + +func (gui *Gui) handlePrevBranchesTab(g *gocui.Gui, v *gocui.View) error { + return gui.onBranchesTabClick( + utils.ModuloWithWrap(v.TabIndex-1, len(v.Tabs)), + ) +} diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 6d198443f..ce3dc91c7 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -403,6 +403,18 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Description: gui.Tr.SLocalize("FastForward"), }, { + ViewName: "branches", + Key: ']', + Modifier: gocui.ModNone, + Handler: gui.handleNextBranchesTab, + }, + { + ViewName: "branches", + Key: '[', + Modifier: gocui.ModNone, + Handler: gui.handlePrevBranchesTab, + }, + { ViewName: "commits", Key: 's', Modifier: gocui.ModNone, diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index bf69fd30e..26d1b9021 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -299,3 +299,14 @@ func DifferenceInt(a, b []int) []int { } return result } + +// used to keep a number n between 0 and max, allowing for wraparounds +func ModuloWithWrap(n, max int) int { + if n >= max { + return n % max + } else if n < 0 { + return max + n + } else { + return n + } +} |