Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/gui/context/list_context_trait.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,7 @@ func (self *ListContextTrait) TotalContentHeight() int {
}
return result
}

func (self *ListContextTrait) IndexForGotoBottom() int {
return self.list.Len() - 1
}
17 changes: 17 additions & 0 deletions pkg/gui/context/local_commits_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
17 changes: 17 additions & 0 deletions pkg/gui/context/sub_commits_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion pkg/gui/controllers/list_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 0 additions & 22 deletions pkg/gui/controllers/local_commits_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,6 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
Description: self.c.Tr.MarkAsBaseCommit,
Tooltip: self.c.Tr.MarkAsBaseCommitTooltip,
},
// overriding this navigation keybinding because we might need to load
// more commits on demand
{
Key: opts.GetKey(opts.Config.Universal.GotoBottom),
Handler: self.gotoBottom,
Description: self.c.Tr.GotoBottom,
Tag: "navigation",
},
}

for _, binding := range outsideFilterModeBindings {
Expand Down Expand Up @@ -1154,20 +1146,6 @@ func (self *LocalCommitsController) openSearch() error {
return self.c.Helpers().Search.OpenSearchPrompt(self.context())
}

func (self *LocalCommitsController) gotoBottom() error {
// we usually lazyload these commits but now that we're jumping to the bottom we need to load them now
if self.context().GetLimitCommits() {
self.context().SetLimitCommits(false)
if err := self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.COMMITS}}); err != nil {
return err
}
}

self.context().SetSelectedLineIdx(self.context().Len() - 1)

return nil
}

func (self *LocalCommitsController) handleOpenLogMenu() error {
return self.c.Menu(types.CreateMenuOptions{
Title: self.c.Tr.LogMenuTitle,
Expand Down
2 changes: 2 additions & 0 deletions pkg/gui/types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ type IListContext interface {
IsListContext() // used for type switch
RangeSelectEnabled() bool
RenderOnlyVisibleLines() bool

IndexForGotoBottom() int
}

type IPatchExplorerContext interface {
Expand Down