diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 424f47c5..0165394d 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -522,6 +522,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { }...) } + // Mapping number keys to jump between side panels + for _, panel := range gui.allSidePanels() { + for idx := 1; idx <= len(gui.allSidePanels()); idx++ { + bindings = append(bindings, &Binding{ViewName: panel.GetView().Name(), Key: rune('0' + idx), Modifier: gocui.ModNone, Handler: wrappedHandlerWithKey(gui.jumpToSideView, idx)}) + } + } + setUpDownClickBindings := func(viewName string, onUp func() error, onDown func() error, onClick func() error) { bindings = append(bindings, []*Binding{ {ViewName: viewName, Key: 'k', Modifier: gocui.ModNone, Handler: wrappedHandler(onUp)}, @@ -602,3 +609,9 @@ func wrappedHandler(f func() error) func(*gocui.Gui, *gocui.View) error { return f() } } + +func wrappedHandlerWithKey(f func(g *gocui.Gui, key int) error, key int) func(*gocui.Gui, *gocui.View) error { + return func(g *gocui.Gui, v *gocui.View) error { + return f(g, key) + } +} diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 5e2b72fb..1c28a9d5 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -64,6 +64,21 @@ func (gui *Gui) previousView(g *gocui.Gui, v *gocui.View) error { return gui.switchFocus(focusedView) } +func (gui *Gui) jumpToSideView(g *gocui.Gui, idx int) error { + sideViewNames := gui.sideViewNames() + if idx < 1 || len(sideViewNames) < idx { + gui.Log.Info("not in list of views") + return nil + } + focusedViewName := sideViewNames[idx-1] + focusedView, err := g.View(focusedViewName) + if err != nil { + panic(err) + } + gui.resetMainView() + return gui.switchFocus(focusedView) +} + func (gui *Gui) resetMainView() { gui.State.Panels.Main.ObjectKey = "" gui.Views.Main.Wrap = gui.Config.UserConfig.Gui.WrapMainPanel