mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-23 12:18:51 +02:00
In other views that show lists of commits (reflog and stash) it doesn't make sense to show a range diff of selected entries because they don't form a linear sequence, so we keep the previous behavior of showing the diff for the free end of the selection range in those view. The same applies to the commits view if the selection range includes rebasing todos; these can have an arbitrary order, and a range diff doesn't make sense for those.
78 lines
2.1 KiB
Go
78 lines
2.1 KiB
Go
package controllers
|
|
|
|
import (
|
|
"github.com/jesseduffield/gocui"
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
)
|
|
|
|
type SubCommitsController struct {
|
|
baseController
|
|
*ListControllerTrait[*models.Commit]
|
|
c *ControllerCommon
|
|
}
|
|
|
|
var _ types.IController = &SubCommitsController{}
|
|
|
|
func NewSubCommitsController(
|
|
c *ControllerCommon,
|
|
) *SubCommitsController {
|
|
return &SubCommitsController{
|
|
baseController: baseController{},
|
|
ListControllerTrait: NewListControllerTrait[*models.Commit](
|
|
c,
|
|
c.Contexts().SubCommits,
|
|
c.Contexts().SubCommits.GetSelected,
|
|
c.Contexts().SubCommits.GetSelectedItems,
|
|
),
|
|
c: c,
|
|
}
|
|
}
|
|
|
|
func (self *SubCommitsController) Context() types.Context {
|
|
return self.context()
|
|
}
|
|
|
|
func (self *SubCommitsController) context() *context.SubCommitsContext {
|
|
return self.c.Contexts().SubCommits
|
|
}
|
|
|
|
func (self *SubCommitsController) GetOnRenderToMain() func() error {
|
|
return func() error {
|
|
return self.c.Helpers().Diff.WithDiffModeCheck(func() error {
|
|
commit := self.context().GetSelected()
|
|
var task types.UpdateTask
|
|
if commit == nil {
|
|
task = types.NewRenderStringTask("No commits")
|
|
} else {
|
|
refRange := self.context().GetSelectedRefRangeForDiffFiles()
|
|
task = self.c.Helpers().Diff.GetUpdateTaskForRenderingCommitsDiff(commit, refRange)
|
|
}
|
|
|
|
return self.c.RenderToMainViews(types.RefreshMainOpts{
|
|
Pair: self.c.MainViewPairs().Normal,
|
|
Main: &types.ViewUpdateOpts{
|
|
Title: "Commit",
|
|
SubTitle: self.c.Helpers().Diff.IgnoringWhitespaceSubTitle(),
|
|
Task: task,
|
|
},
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
func (self *SubCommitsController) GetOnFocus() func(types.OnFocusOpts) error {
|
|
return func(types.OnFocusOpts) error {
|
|
context := self.context()
|
|
if context.GetSelectedLineIdx() > COMMIT_THRESHOLD && context.GetLimitCommits() {
|
|
context.SetLimitCommits(false)
|
|
self.c.OnWorker(func(_ gocui.Task) error {
|
|
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUB_COMMITS}})
|
|
})
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|