diff options
author | Michael Muré <batolettre@gmail.com> | 2018-12-23 21:16:27 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-12-23 21:16:27 +0100 |
commit | fb87d44888ff7d7e528156c6d4b7b508e17ddbae (patch) | |
tree | 2ea7e285bd45a05342021079eceb199ded2468b5 | |
parent | 87098cee7b70679849e76ba608f28f1b94a5316e (diff) | |
download | git-bug-fb87d44888ff7d7e528156c6d4b7b508e17ddbae.tar.gz |
termui: don't reset the cursor when paginating with left/right
See https://github.com/MichaelMure/git-bug/pull/83 for the rationale
-rw-r--r-- | termui/bug_table.go | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/termui/bug_table.go b/termui/bug_table.go index 36ce7525..091e9b99 100644 --- a/termui/bug_table.go +++ b/termui/bug_table.go @@ -343,7 +343,17 @@ func (bt *bugTable) cursorDown(g *gocui.Gui, v *gocui.View) error { // 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) + _, 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) @@ -359,7 +369,17 @@ func (bt *bugTable) cursorUp(g *gocui.Gui, v *gocui.View) error { // If we are at the top of the page, switch to the previous one. if y-1 < 0 { - return bt.previousPage(g, v) + _, 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) @@ -391,8 +411,6 @@ func (bt *bugTable) nextPage(g *gocui.Gui, v *gocui.View) error { } bt.pageCursor += max - bt.selectCursor = 0 - _ = v.SetCursor(0, bt.selectCursor) return bt.doPaginate(max) } @@ -403,9 +421,8 @@ func (bt *bugTable) previousPage(g *gocui.Gui, v *gocui.View) error { 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) } |