summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-03-28 13:44:20 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-03-28 14:02:53 +1100
commit229f5ee48c75ca0c8a78345f9da44dc4b2b2e625 (patch)
treec30bdf055d06816272814406d2aed15477bfa724
parent96c7741ba06359cbc253e615e3160a905512330c (diff)
add keybindings for paging in list panels and jumping to top/bottom
-rw-r--r--docs/Config.md4
-rw-r--r--pkg/config/app_config.go4
-rw-r--r--pkg/gui/keybindings.go4
-rw-r--r--pkg/gui/list_view.go34
4 files changed, 46 insertions, 0 deletions
diff --git a/docs/Config.md b/docs/Config.md
index 41fa68f27..9bf9e45af 100644
--- a/docs/Config.md
+++ b/docs/Config.md
@@ -53,6 +53,10 @@ Default path for the config file:
nextItem: '<down>' # go one line down
prevItem-alt: 'k' # go one line up
nextItem-alt: 'j' # go one line down
+ prevPage: ',' # go to next page in list
+ nextPage: '.' # go to previous page in list
+ gotoTop: '<' # go to top of list
+ gotoBottom: '>' # go to bottom of list
prevBlock: '<left>' # goto the previous block / panel
nextBlock: '<right>' # goto the next block / panel
prevBlock-alt: 'h' # goto the previous block / panel
diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go
index 310ca9a01..b9b9f892b 100644
--- a/pkg/config/app_config.go
+++ b/pkg/config/app_config.go
@@ -283,6 +283,10 @@ keybinding:
nextItem: '<down>'
prevItem-alt: 'k'
nextItem-alt: 'j'
+ prevPage: ','
+ nextPage: '.'
+ gotoTop: '<'
+ gotoBottom: '>'
prevBlock: '<left>'
nextBlock: '<right>'
prevBlock-alt: 'h'
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 31096a759..c7b9546ad 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -1510,6 +1510,10 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gocui.MouseWheelUp, Modifier: gocui.ModNone, Handler: listView.handlePrevLine},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.nextItem-alt"), Modifier: gocui.ModNone, Handler: listView.handleNextLine},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.nextItem"), Modifier: gocui.ModNone, Handler: listView.handleNextLine},
+ {ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.prevPage"), Modifier: gocui.ModNone, Handler: listView.handlePrevPage},
+ {ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.nextPage"), Modifier: gocui.ModNone, Handler: listView.handleNextPage},
+ {ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.gotoTop"), Modifier: gocui.ModNone, Handler: listView.handleGotoTop},
+ {ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.gotoBottom"), Modifier: gocui.ModNone, Handler: listView.handleGotoBottom},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: listView.handleNextLine},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gocui.MouseLeft, Modifier: gocui.ModNone, Handler: listView.handleClick},
}...)
diff --git a/pkg/gui/list_view.go b/pkg/gui/list_view.go
index 90ea7b8b0..99039eb13 100644
--- a/pkg/gui/list_view.go
+++ b/pkg/gui/list_view.go
@@ -42,6 +42,40 @@ func (lv *listView) handleLineChange(change int) error {
return lv.handleItemSelect(lv.gui.g, view)
}
+func (lv *listView) handleNextPage(g *gocui.Gui, v *gocui.View) error {
+ view, err := lv.gui.g.View(lv.viewName)
+ if err != nil {
+ return nil
+ }
+ _, height := view.Size()
+ delta := height - 1
+ if delta == 0 {
+ delta = 1
+ }
+ return lv.handleLineChange(delta)
+}
+
+func (lv *listView) handleGotoTop(g *gocui.Gui, v *gocui.View) error {
+ return lv.handleLineChange(-lv.getItemsLength())
+}
+
+func (lv *listView) handleGotoBottom(g *gocui.Gui, v *gocui.View) error {
+ return lv.handleLineChange(lv.getItemsLength())
+}
+
+func (lv *listView) handlePrevPage(g *gocui.Gui, v *gocui.View) error {
+ view, err := lv.gui.g.View(lv.viewName)
+ if err != nil {
+ return nil
+ }
+ _, height := view.Size()
+ delta := height - 1
+ if delta == 0 {
+ delta = 1
+ }
+ return lv.handleLineChange(-delta)
+}
+
func (lv *listView) handleClick(g *gocui.Gui, v *gocui.View) error {
if !lv.gui.isPopupPanel(lv.viewName) && lv.gui.popupPanelFocused() {
return nil