Skip to content

Commit 636b94c

Browse files
committed
Make '>' first jump to the beginning of the branch, and only then to the first commit
1 parent 1a880f9 commit 636b94c

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

pkg/gui/context/list_context_trait.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,7 @@ func (self *ListContextTrait) TotalContentHeight() int {
149149
}
150150
return result
151151
}
152+
153+
func (self *ListContextTrait) IndexForGotoBottom() int {
154+
return self.list.Len() - 1
155+
}

pkg/gui/context/local_commits_context.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,20 @@ func searchModelCommits(caseSensitive bool, commits []*models.Commit, columnPosi
289289
strings.Contains(normalize(commit.ExtraInfo), searchStr) // allow searching for tags
290290
})
291291
}
292+
293+
func (self *LocalCommitsContext) IndexForGotoBottom() int {
294+
commits := self.GetCommits()
295+
selectedIdx := self.GetSelectedLineIdx()
296+
if selectedIdx >= 0 && selectedIdx < len(commits)-1 {
297+
if commits[selectedIdx+1].Status != models.StatusMerged {
298+
_, idx, found := lo.FindIndexOf(commits, func(c *models.Commit) bool {
299+
return c.Status == models.StatusMerged
300+
})
301+
if found {
302+
return idx - 1
303+
}
304+
}
305+
}
306+
307+
return self.list.Len() - 1
308+
}

pkg/gui/context/sub_commits_context.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,20 @@ func (self *SubCommitsContext) RefForAdjustingLineNumberInDiff() string {
227227
func (self *SubCommitsContext) ModelSearchResults(searchStr string, caseSensitive bool) []gocui.SearchPosition {
228228
return searchModelCommits(caseSensitive, self.GetCommits(), self.ColumnPositions(), searchStr)
229229
}
230+
231+
func (self *SubCommitsContext) IndexForGotoBottom() int {
232+
commits := self.GetCommits()
233+
selectedIdx := self.GetSelectedLineIdx()
234+
if selectedIdx >= 0 && selectedIdx < len(commits)-1 {
235+
if commits[selectedIdx+1].Status != models.StatusMerged {
236+
_, idx, found := lo.FindIndexOf(commits, func(c *models.Commit) bool {
237+
return c.Status == models.StatusMerged
238+
})
239+
if found {
240+
return idx - 1
241+
}
242+
}
243+
}
244+
245+
return self.list.Len() - 1
246+
}

pkg/gui/controllers/list_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ func (self *ListController) HandleGotoTop() error {
138138
}
139139

140140
func (self *ListController) HandleGotoBottom() error {
141-
return self.handleLineChange(self.context.GetList().Len())
141+
bottomIdx := self.context.IndexForGotoBottom()
142+
change := bottomIdx - self.context.GetList().GetSelectedLineIdx()
143+
return self.handleLineChange(change)
142144
}
143145

144146
func (self *ListController) HandleToggleRangeSelect() error {

pkg/gui/types/context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ type IListContext interface {
180180
IsListContext() // used for type switch
181181
RangeSelectEnabled() bool
182182
RenderOnlyVisibleLines() bool
183+
184+
IndexForGotoBottom() int
183185
}
184186

185187
type IPatchExplorerContext interface {

0 commit comments

Comments
 (0)