aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-12-25 20:12:20 +0100
committerGitHub <noreply@github.com>2018-12-25 20:12:20 +0100
commit60d44f750ed7929e90a394e232f069e47bc78170 (patch)
treed55efd490d8ecfd42e0a5de6320092d509fc7f58
parent96f514168f17136fe02519ab4599a407cd0cc5cb (diff)
parentfb87d44888ff7d7e528156c6d4b7b508e17ddbae (diff)
downloadgit-bug-60d44f750ed7929e90a394e232f069e47bc78170.tar.gz
Merge pull request #83 from Steap/improve-termui-paging
Improve termui paging
-rw-r--r--termui/bug_table.go38
1 files changed, 36 insertions, 2 deletions
diff --git a/termui/bug_table.go b/termui/bug_table.go
index 1545dbc9..091e9b99 100644
--- a/termui/bug_table.go
+++ b/termui/bug_table.go
@@ -340,8 +340,23 @@ 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 {
+ _, max := v.Size()
+
+ if bt.pageCursor+max >= len(bt.allIds) {
+ return nil
+ }
+
+ bt.pageCursor += max
+ bt.selectCursor = 0
+ _ = v.SetCursor(0, bt.selectCursor)
+
+ return bt.doPaginate(max)
+ }
+
+ 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 +366,23 @@ 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 {
+ _, max := v.Size()
+
+ if bt.pageCursor == 0 {
+ return nil
+ }
+
+ bt.pageCursor = maxInt(0, bt.pageCursor-max)
+ bt.selectCursor = max - 1
+ _ = v.SetCursor(0, bt.selectCursor)
+
+ return bt.doPaginate(max)
+ }
+
+ y = maxInt(y-1, 0)
// window is too small to set the cursor properly, ignoring the error
_ = v.SetCursor(0, y)
bt.selectCursor = y
@@ -388,6 +418,10 @@ func (bt *bugTable) nextPage(g *gocui.Gui, v *gocui.View) error {
func (bt *bugTable) previousPage(g *gocui.Gui, v *gocui.View) error {
_, max := v.Size()
+ if bt.pageCursor == 0 {
+ return nil
+ }
+
bt.pageCursor = maxInt(0, bt.pageCursor-max)
return bt.doPaginate(max)