mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-25 22:32:13 +02:00
Expose SelectedCommit to custom commands, deprecate Selected{Local,Reflog,Sub}Commit
SelectedCommit is context-dependent and points to SelectedLocalCommit, SelectedReflogCommit, or SelectedSubCommit depending on which panel is active. If none of these panels is active, it returns the selected local commit, which is probably the most useful default (e.g. when defining custom commands for the Files panel).
This commit is contained in:
@@ -164,9 +164,10 @@ func worktreeShimFromModelRemote(worktree *models.Worktree) *Worktree {
|
||||
|
||||
// SessionState captures the current state of the application for use in custom commands
|
||||
type SessionState struct {
|
||||
SelectedLocalCommit *Commit
|
||||
SelectedReflogCommit *Commit
|
||||
SelectedSubCommit *Commit
|
||||
SelectedLocalCommit *Commit // deprecated, use SelectedCommit
|
||||
SelectedReflogCommit *Commit // deprecated, use SelectedCommit
|
||||
SelectedSubCommit *Commit // deprecated, use SelectedCommit
|
||||
SelectedCommit *Commit
|
||||
SelectedFile *File
|
||||
SelectedPath string
|
||||
SelectedLocalBranch *Branch
|
||||
@@ -181,11 +182,24 @@ type SessionState struct {
|
||||
}
|
||||
|
||||
func (self *SessionStateLoader) call() *SessionState {
|
||||
selectedLocalCommit := commitShimFromModelCommit(self.c.Contexts().LocalCommits.GetSelected())
|
||||
selectedReflogCommit := commitShimFromModelCommit(self.c.Contexts().ReflogCommits.GetSelected())
|
||||
selectedSubCommit := commitShimFromModelCommit(self.c.Contexts().SubCommits.GetSelected())
|
||||
|
||||
selectedCommit := selectedLocalCommit
|
||||
if self.c.Context().IsCurrentOrParent(self.c.Contexts().ReflogCommits) {
|
||||
selectedCommit = selectedReflogCommit
|
||||
} else if self.c.Context().IsCurrentOrParent(self.c.Contexts().SubCommits) {
|
||||
selectedCommit = selectedSubCommit
|
||||
}
|
||||
|
||||
return &SessionState{
|
||||
SelectedFile: fileShimFromModelFile(self.c.Contexts().Files.GetSelectedFile()),
|
||||
SelectedPath: self.c.Contexts().Files.GetSelectedPath(),
|
||||
SelectedLocalCommit: commitShimFromModelCommit(self.c.Contexts().LocalCommits.GetSelected()),
|
||||
SelectedReflogCommit: commitShimFromModelCommit(self.c.Contexts().ReflogCommits.GetSelected()),
|
||||
SelectedLocalCommit: selectedLocalCommit,
|
||||
SelectedReflogCommit: selectedReflogCommit,
|
||||
SelectedSubCommit: selectedSubCommit,
|
||||
SelectedCommit: selectedCommit,
|
||||
SelectedLocalBranch: branchShimFromModelBranch(self.c.Contexts().Branches.GetSelected()),
|
||||
SelectedRemoteBranch: remoteBranchShimFromModelRemoteBranch(self.c.Contexts().RemoteBranches.GetSelected()),
|
||||
SelectedRemote: remoteShimFromModelRemote(self.c.Contexts().Remotes.GetSelected()),
|
||||
@@ -193,7 +207,6 @@ func (self *SessionStateLoader) call() *SessionState {
|
||||
SelectedStashEntry: stashEntryShimFromModelRemote(self.c.Contexts().Stash.GetSelected()),
|
||||
SelectedCommitFile: commitFileShimFromModelRemote(self.c.Contexts().CommitFiles.GetSelectedFile()),
|
||||
SelectedCommitFilePath: self.c.Contexts().CommitFiles.GetSelectedPath(),
|
||||
SelectedSubCommit: commitShimFromModelCommit(self.c.Contexts().SubCommits.GetSelected()),
|
||||
SelectedWorktree: worktreeShimFromModelRemote(self.c.Contexts().Worktrees.GetSelected()),
|
||||
CheckedOutBranch: branchShimFromModelBranch(self.refsHelper.GetCheckedOutRef()),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user