mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-08-24 10:13:41 -05:00
Every one of these did by hand what focusing the list now does on its own: five hand-added scroll requests, and four origin resets that paired a "select the first item" with a "and show the top of the list". The scroll that the commits refresh performed when it found the selected commit at a new index goes too. It is now unconditional for a foreground refresh, and deliberately absent for a background one: when an agent commits in another window, we would rather see the new commits arrive than have the view yank itself back to the commit we had selected. The one origin reset that stays is the one in ReApplyFilter, which runs as part of a refresh and so can't rely on the refresh scrolling. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
73 lines
2.2 KiB
Go
73 lines
2.2 KiB
Go
package helpers
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
|
)
|
|
|
|
type SubCommitsHelper struct {
|
|
c *HelperCommon
|
|
|
|
refreshHelper *RefreshHelper
|
|
}
|
|
|
|
func NewSubCommitsHelper(
|
|
c *HelperCommon,
|
|
refreshHelper *RefreshHelper,
|
|
) *SubCommitsHelper {
|
|
return &SubCommitsHelper{
|
|
c: c,
|
|
refreshHelper: refreshHelper,
|
|
}
|
|
}
|
|
|
|
type ViewSubCommitsOpts struct {
|
|
Ref models.Ref
|
|
RefToShowDivergenceFrom string
|
|
TitleRef string
|
|
Context types.Context
|
|
ShowBranchHeads bool
|
|
}
|
|
|
|
func (self *SubCommitsHelper) ViewSubCommits(opts ViewSubCommitsOpts) error {
|
|
commits, err := self.c.Git().Loaders.CommitLoader.GetCommits(
|
|
git_commands.GetCommitsOptions{
|
|
Limit: true,
|
|
FilterPath: self.c.Modes().Filtering.GetPath(),
|
|
FilterAuthor: self.c.Modes().Filtering.GetAuthor(),
|
|
IncludeRebaseCommits: false,
|
|
RefName: opts.Ref.FullRefName(),
|
|
RefForPushedStatus: opts.Ref,
|
|
RefToShowDivergenceFrom: opts.RefToShowDivergenceFrom,
|
|
MainBranches: self.c.Model().MainBranches,
|
|
HashPool: self.c.Model().HashPool,
|
|
},
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
self.c.Model().SubCommits = commits
|
|
self.refreshHelper.RefreshAuthors(commits)
|
|
|
|
subCommitsContext := self.c.Contexts().SubCommits
|
|
subCommitsContext.SetSelection(0)
|
|
subCommitsContext.SetParentContext(opts.Context)
|
|
subCommitsContext.SetWindowName(opts.Context.GetWindowName())
|
|
subCommitsContext.SetTitleRef(utils.TruncateWithEllipsis(opts.TitleRef, 50))
|
|
subCommitsContext.SetRef(opts.Ref)
|
|
subCommitsContext.SetRefToShowDivergenceFrom(opts.RefToShowDivergenceFrom)
|
|
subCommitsContext.SetLimitCommits(true)
|
|
subCommitsContext.SetShowBranchHeads(opts.ShowBranchHeads)
|
|
subCommitsContext.ClearSearchString()
|
|
subCommitsContext.GetView().ClearSearch()
|
|
subCommitsContext.GetView().TitlePrefix = opts.Context.GetView().TitlePrefix
|
|
|
|
self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)
|
|
|
|
self.c.Context().Push(self.c.Contexts().SubCommits, types.OnFocusOpts{})
|
|
return nil
|
|
}
|