From 5e712ed87d7379eda33e60daae5ac1ced46d45c9 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 8 May 2025 15:37:35 +0200 Subject: [PATCH] Make '>' first jump to the beginning of the branch, and only then to the first commit --- pkg/gui/context/list_context_trait.go | 4 ++++ pkg/gui/context/local_commits_context.go | 17 +++++++++++++++++ pkg/gui/context/sub_commits_context.go | 17 +++++++++++++++++ pkg/gui/controllers/list_controller.go | 4 +++- pkg/gui/types/context.go | 2 ++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/pkg/gui/context/list_context_trait.go b/pkg/gui/context/list_context_trait.go index 25616af0a..cb435c035 100644 --- a/pkg/gui/context/list_context_trait.go +++ b/pkg/gui/context/list_context_trait.go @@ -149,3 +149,7 @@ func (self *ListContextTrait) TotalContentHeight() int { } return result } + +func (self *ListContextTrait) IndexForGotoBottom() int { + return self.list.Len() - 1 +} diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index 6f92b34fa..6a2a20c8d 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -289,3 +289,20 @@ func searchModelCommits(caseSensitive bool, commits []*models.Commit, columnPosi strings.Contains(normalize(commit.ExtraInfo), searchStr) // allow searching for tags }) } + +func (self *LocalCommitsContext) IndexForGotoBottom() int { + commits := self.GetCommits() + selectedIdx := self.GetSelectedLineIdx() + if selectedIdx >= 0 && selectedIdx < len(commits)-1 { + if commits[selectedIdx+1].Status != models.StatusMerged { + _, idx, found := lo.FindIndexOf(commits, func(c *models.Commit) bool { + return c.Status == models.StatusMerged + }) + if found { + return idx - 1 + } + } + } + + return self.list.Len() - 1 +} diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go index 650a577c1..ac28aca2e 100644 --- a/pkg/gui/context/sub_commits_context.go +++ b/pkg/gui/context/sub_commits_context.go @@ -227,3 +227,20 @@ func (self *SubCommitsContext) RefForAdjustingLineNumberInDiff() string { func (self *SubCommitsContext) ModelSearchResults(searchStr string, caseSensitive bool) []gocui.SearchPosition { return searchModelCommits(caseSensitive, self.GetCommits(), self.ColumnPositions(), searchStr) } + +func (self *SubCommitsContext) IndexForGotoBottom() int { + commits := self.GetCommits() + selectedIdx := self.GetSelectedLineIdx() + if selectedIdx >= 0 && selectedIdx < len(commits)-1 { + if commits[selectedIdx+1].Status != models.StatusMerged { + _, idx, found := lo.FindIndexOf(commits, func(c *models.Commit) bool { + return c.Status == models.StatusMerged + }) + if found { + return idx - 1 + } + } + } + + return self.list.Len() - 1 +} diff --git a/pkg/gui/controllers/list_controller.go b/pkg/gui/controllers/list_controller.go index 42f15d895..36ac1ba91 100644 --- a/pkg/gui/controllers/list_controller.go +++ b/pkg/gui/controllers/list_controller.go @@ -138,7 +138,9 @@ func (self *ListController) HandleGotoTop() error { } func (self *ListController) HandleGotoBottom() error { - return self.handleLineChange(self.context.GetList().Len()) + bottomIdx := self.context.IndexForGotoBottom() + change := bottomIdx - self.context.GetList().GetSelectedLineIdx() + return self.handleLineChange(change) } func (self *ListController) HandleToggleRangeSelect() error { diff --git a/pkg/gui/types/context.go b/pkg/gui/types/context.go index f76bedeb6..b75d97fb6 100644 --- a/pkg/gui/types/context.go +++ b/pkg/gui/types/context.go @@ -180,6 +180,8 @@ type IListContext interface { IsListContext() // used for type switch RangeSelectEnabled() bool RenderOnlyVisibleLines() bool + + IndexForGotoBottom() int } type IPatchExplorerContext interface {