Termui: switch to the previous/next page when going up/down.

Cyril Roelandt created

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.

Change summary

termui/bug_table.go | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

Detailed changes

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