diff --git a/modules/github/display.go b/modules/github/display.go index d896f51c..45e38ac0 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -12,7 +12,6 @@ func (widget *Widget) display() { func (widget *Widget) content() (string, string, bool) { repo := widget.currentGithubRepo() - widget.Unselect() title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.title(repo)) if repo == nil { @@ -38,20 +37,17 @@ func (widget *Widget) content() (string, string, bool) { func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) string { prs := repo.myPullRequests(username, widget.settings.enableStatus) - numSelections := widget.GetSelected() - if len(prs) == 0 { return " [grey]none[white]\n" } - str := "" - for _, pr := range prs { - str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, numSelections, *pr.Number, *pr.Title) - str += "\n" - numSelections++ - } + widget.SetItemCount(len(prs)) - widget.SetItemCount(numSelections) + str := "" + for idx, pr := range prs { + str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, idx, *pr.Number, *pr.Title) + str += "\n" + } return str } @@ -59,7 +55,7 @@ func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) s func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPage int) string { res := repo.customIssueQuery(filter, perPage) - numSelections := widget.GetSelected() + maxItems := widget.GetItemCount() if res == nil { return " [grey]Invalid Query[white]\n" @@ -70,13 +66,12 @@ func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPag } str := "" - for _, issue := range res.Issues { - str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, numSelections, *issue.Number, *issue.Title) + for idx, issue := range res.Issues { + str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, maxItems + idx, *issue.Number, *issue.Title) str += "\n" - numSelections++ } - widget.SetItemCount(numSelections) + widget.SetItemCount(maxItems + len(res.Issues)) return str } @@ -84,20 +79,19 @@ func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPag func (widget *Widget) displayMyReviewRequests(repo *GithubRepo, username string) string { prs := repo.myReviewRequests(username) - numSelections := widget.GetSelected() + maxItems := widget.GetItemCount() if len(prs) == 0 { return " [grey]none[white]\n" } str := "" - for _, pr := range prs { - str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, numSelections, *pr.Number, *pr.Title) + for idx, pr := range prs { + str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, maxItems + idx, *pr.Number, *pr.Title) str += "\n" - numSelections++ } - widget.SetItemCount(numSelections) + widget.SetItemCount(maxItems + len(prs)) return str } diff --git a/modules/github/keyboard.go b/modules/github/keyboard.go index 60229f58..ce3d2ace 100644 --- a/modules/github/keyboard.go +++ b/modules/github/keyboard.go @@ -19,4 +19,5 @@ func (widget *Widget) initializeKeyboardControls() { widget.SetKeyboardKey(tcell.KeyLeft, widget.PrevSource, "Select previous source") widget.SetKeyboardKey(tcell.KeyEnter, widget.openPr, "Open PR in browser") widget.SetKeyboardKey(tcell.KeyInsert, widget.openRepo, "Open item in browser") + widget.SetKeyboardKey(tcell.KeyEsc, widget.Unselect, "Clear selection") } diff --git a/modules/github/widget.go b/modules/github/widget.go index 8a2f6403..380b07b6 100644 --- a/modules/github/widget.go +++ b/modules/github/widget.go @@ -51,6 +51,10 @@ func (widget *Widget) SetItemCount(items int) { widget.maxItems = items } +func (widget *Widget) GetItemCount() int { + return widget.maxItems +} + func (widget *Widget) GetSelected() int { if widget.Selected < 0 { return 0 @@ -76,6 +80,7 @@ func (widget *Widget) Prev() { func (widget *Widget) Unselect() { widget.Selected = -1 + widget.View.Highlight(strconv.Itoa(widget.Selected)).ScrollToHighlight() } func (widget *Widget) Refresh() { @@ -83,6 +88,7 @@ func (widget *Widget) Refresh() { repo.Refresh() } + widget.SetItemCount(0) widget.display() }