From 1174265e598c40863fc1a16d1b1583aafa0dcd6d Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Sat, 22 Dec 2018 00:06:40 +0100 Subject: [PATCH 1/3] 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 From 87098cee7b70679849e76ba608f28f1b94a5316e Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Sat, 22 Dec 2018 00:43:59 +0100 Subject: [PATCH 2/3] Termui: Better position the cursor when changing page. After moving to the previous page, users probably want to have their cursor on the last entry of the page. When moving to the next page, they probably want it to be on the first entry. --- termui/bug_table.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/termui/bug_table.go b/termui/bug_table.go index cb3f6964a84710e635dff0a0aacb4c2586d94bde..36ce7525e2745494c1ea5da271245b86a580d54e 100644 --- a/termui/bug_table.go +++ b/termui/bug_table.go @@ -391,6 +391,8 @@ 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) } @@ -398,7 +400,12 @@ 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) + bt.selectCursor = max - 1 + _ = v.SetCursor(0, bt.selectCursor) return bt.doPaginate(max) } From fb87d44888ff7d7e528156c6d4b7b508e17ddbae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sun, 23 Dec 2018 21:16:27 +0100 Subject: [PATCH 3/3] 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(-) diff --git a/termui/bug_table.go b/termui/bug_table.go index 36ce7525e2745494c1ea5da271245b86a580d54e..091e9b993a9a90ba822833386da2e670997379fd 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) }