1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

using the correct order and maintaining scroll position when changing source

This commit is contained in:
Joel Valentine 2019-08-31 18:58:25 +01:00
parent 5740b689be
commit 74d2fbe833
2 changed files with 16 additions and 12 deletions

View File

@ -12,6 +12,15 @@ func (widget *Widget) display() {
func (widget *Widget) content() (string, string, bool) { func (widget *Widget) content() (string, string, bool) {
repo := widget.currentGithubRepo() 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)) title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.title(repo))
if repo == nil { if repo == nil {
return title, " GitHub repo data is unavailable ", false 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 { func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) string {
prs := repo.myPullRequests(username, widget.settings.enableStatus) prs := repo.myPullRequests(username, widget.settings.enableStatus)
prLength := len(prs) prLength := len(prs)
if prLength == 0 { if prLength == 0 {
return " [grey]none[white]\n" return " [grey]none[white]\n"
} }
widget.SetItemCount(prLength) maxItems := widget.GetItemCount()
str := "" str := ""
for idx, pr := range prs { 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" str += "\n"
} }
widget.SetItemCount(maxItems + prLength)
return str return str
} }
@ -82,22 +93,16 @@ func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPag
func (widget *Widget) displayMyReviewRequests(repo *GithubRepo, username string) string { func (widget *Widget) displayMyReviewRequests(repo *GithubRepo, username string) string {
prs := repo.myReviewRequests(username) prs := repo.myReviewRequests(username)
prLength := len(prs) if len(prs) == 0 {
if prLength == 0 {
return " [grey]none[white]\n" return " [grey]none[white]\n"
} }
maxItems := widget.GetItemCount()
str := "" str := ""
for idx, pr := range prs { 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" str += "\n"
} }
widget.SetItemCount(maxItems + prLength)
return str return str
} }

View File

@ -88,7 +88,6 @@ func (widget *Widget) Refresh() {
repo.Refresh() repo.Refresh()
} }
widget.SetItemCount(0)
widget.display() widget.display()
} }