From fb87d44888ff7d7e528156c6d4b7b508e17ddbae Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 23 Dec 2018 21:16:27 +0100 Subject: termui: don't reset the cursor when paginating with left/right See https://github.com/MichaelMure/git-bug/pull/83 for the rationale --- termui/bug_table.go | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'termui') 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) } -- cgit