From 74d2fbe833cdc930ecdf01c36d38547e9821421d Mon Sep 17 00:00:00 2001 From: Joel Valentine Date: Sat, 31 Aug 2019 18:58:25 +0100 Subject: [PATCH] using the correct order and maintaining scroll position when changing source --- modules/github/display.go | 27 ++++++++++++++++----------- modules/github/widget.go | 1 - 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/github/display.go b/modules/github/display.go index b75dfc90..8ea0fb0a 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -12,6 +12,15 @@ func (widget *Widget) display() { func (widget *Widget) content() (string, string, bool) { repo := widget.currentGithubRepo() + + if len(widget.View.GetHighlights()) > 0 { + widget.View.ScrollToHighlight() + } else { + widget.View.ScrollToBeginning() + } + + widget.SetItemCount(len(repo.myReviewRequests((widget.settings.username)))) + title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.title(repo)) if repo == nil { return title, " GitHub repo data is unavailable ", false @@ -35,21 +44,23 @@ func (widget *Widget) content() (string, string, bool) { func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) string { prs := repo.myPullRequests(username, widget.settings.enableStatus) - + prLength := len(prs) if prLength == 0 { return " [grey]none[white]\n" } - widget.SetItemCount(prLength) + maxItems := widget.GetItemCount() str := "" for idx, pr := range prs { - str += fmt.Sprintf(`%s[green]["%d"]%4d[""][white] %s`, widget.mergeString(pr), idx, *pr.Number, *pr.Title) + str += fmt.Sprintf(`%s[green]["%d"]%4d[""][white] %s`, widget.mergeString(pr), maxItems + idx, *pr.Number, *pr.Title) str += "\n" } + widget.SetItemCount(maxItems + prLength) + return str } @@ -82,22 +93,16 @@ func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPag func (widget *Widget) displayMyReviewRequests(repo *GithubRepo, username string) string { prs := repo.myReviewRequests(username) - prLength := len(prs) - - if prLength == 0 { + if len(prs) == 0 { return " [grey]none[white]\n" } - maxItems := widget.GetItemCount() - str := "" for idx, pr := range prs { - str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, maxItems + idx, *pr.Number, *pr.Title) + str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, idx, *pr.Number, *pr.Title) str += "\n" } - widget.SetItemCount(maxItems + prLength) - return str } diff --git a/modules/github/widget.go b/modules/github/widget.go index 380b07b6..e8de805a 100644 --- a/modules/github/widget.go +++ b/modules/github/widget.go @@ -88,7 +88,6 @@ func (widget *Widget) Refresh() { repo.Refresh() } - widget.SetItemCount(0) widget.display() }