From 1174265e598c40863fc1a16d1b1583aafa0dcd6d Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Sat, 22 Dec 2018 00:06:40 +0100 Subject: [PATCH] Termui: switch to the previous/next page when going up/down. Rather than using 'h' or 'l' to load the previous or next page, allow users to do this automatically when going up or down the list with 'k' or 'j'. This is the default behaviour in mutt, for instance. --- termui/bug_table.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/termui/bug_table.go b/termui/bug_table.go index 1545dbc914f09980be36a2386e3e8f37d295916c..cb3f6964a84710e635dff0a0aacb4c2586d94bde 100644 --- a/termui/bug_table.go +++ b/termui/bug_table.go @@ -340,8 +340,13 @@ func (bt *bugTable) renderFooter(v *gocui.View, maxX int) { func (bt *bugTable) cursorDown(g *gocui.Gui, v *gocui.View) error { _, y := v.Cursor() - y = minInt(y+1, bt.getTableLength()-1) + // If we are at the bottom of the page, switch to the next one. + if y+1 > bt.getTableLength()-1 { + return bt.nextPage(g, v) + } + + y = minInt(y+1, bt.getTableLength()-1) // window is too small to set the cursor properly, ignoring the error _ = v.SetCursor(0, y) bt.selectCursor = y @@ -351,8 +356,13 @@ func (bt *bugTable) cursorDown(g *gocui.Gui, v *gocui.View) error { func (bt *bugTable) cursorUp(g *gocui.Gui, v *gocui.View) error { _, y := v.Cursor() - y = maxInt(y-1, 0) + // If we are at the top of the page, switch to the previous one. + if y-1 < 0 { + return bt.previousPage(g, v) + } + + y = maxInt(y-1, 0) // window is too small to set the cursor properly, ignoring the error _ = v.SetCursor(0, y) bt.selectCursor = y