mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-06 05:57:38 -04:00
Five panels show a commit's diff in the focused main view — one file of it from the commit files panel, the whole of it from the commits, sub-commits, stash and reflog panels — and each answered for that diff itself, in the same words. Have them share one object instead, told only which diff it is, so that what follows has a single place to say what can be done to a commit's diff and needs saying once rather than five times. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
46 lines
1.6 KiB
Go
46 lines
1.6 KiB
Go
package controllers
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
)
|
|
|
|
// CommitDiffActions implements what a panel showing a commit's diff offers on that diff
|
|
// in the focused main view. Five panels do: the commit files panel shows the diff of one
|
|
// file of a commit, and the commits, sub-commits, stash and reflog panels the whole diff
|
|
// of whatever they have selected. They all offer the same thing and differ only in which
|
|
// diff they show, so they share this, each saying which diff that is.
|
|
type CommitDiffActions struct {
|
|
c *ControllerCommon
|
|
|
|
// The panel this belongs to, and what it is showing the diff of — nil when it has
|
|
// nothing selected, and so no diff.
|
|
panel types.Context
|
|
target func() *commitDiffTarget
|
|
}
|
|
|
|
// commitDiffTarget is the diff a panel is showing: the two ends of it, and whether it
|
|
// belongs to a commit lazygit may rewrite.
|
|
type commitDiffTarget struct {
|
|
from string
|
|
to string
|
|
canRebase bool
|
|
}
|
|
|
|
var _ types.FocusedMainViewDiffSource = &CommitDiffActions{}
|
|
|
|
func NewCommitDiffActions(
|
|
c *ControllerCommon, panel types.Context, target func() *commitDiffTarget,
|
|
) *CommitDiffActions {
|
|
return &CommitDiffActions{c: c, panel: panel, target: target}
|
|
}
|
|
|
|
// PlainDiff hands out the diff the panel is showing, for the given files — the same
|
|
// diff as in the main view, only without the commit's message and stat above it.
|
|
func (self *CommitDiffActions) PlainDiff(_ types.DiffPaneContext, paths []string) string {
|
|
target := self.target()
|
|
if target == nil {
|
|
return ""
|
|
}
|
|
return self.c.Helpers().Diff.PlainDiffBetweenRefs(target.from, target.to, paths)
|
|
}
|