mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-04 23:37:41 +02:00
Split behavior of rendering allBranchesLogCmd and switching to next cmd (#4574)
- **PR Description** This is a recreation of https://github.com/jesseduffield/lazygit/pull/4556. Compared to that PR description, this has actually solved the problem that repeated attempts to `1` `a` when `gui.statusPanelView: dashboard`. Now we only rotate logs on the 2nd `a` press. While this does differ from current behavior, I believe it is better, and I have more details in my commit description. Fixes https://github.com/jesseduffield/lazygit/issues/4469
This commit is contained in:
commit
43efdded4a
@ -255,18 +255,24 @@ func (self *BranchCommands) Merge(branchName string, opts MergeOpts) error {
|
|||||||
return self.cmd.New(cmdArgs).Run()
|
return self.cmd.New(cmdArgs).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *BranchCommands) AllBranchesLogCmdObj() *oscommands.CmdObj {
|
// Only choose between non-empty, non-identical commands
|
||||||
// Only choose between non-empty, non-identical commands
|
func (self *BranchCommands) allBranchesLogCandidates() []string {
|
||||||
candidates := lo.Uniq(lo.WithoutEmpty(self.UserConfig().Git.AllBranchesLogCmds))
|
return lo.Uniq(lo.WithoutEmpty(self.UserConfig().Git.AllBranchesLogCmds))
|
||||||
|
}
|
||||||
|
|
||||||
n := len(candidates)
|
func (self *BranchCommands) AllBranchesLogCmdObj() *oscommands.CmdObj {
|
||||||
|
candidates := self.allBranchesLogCandidates()
|
||||||
|
|
||||||
i := self.allBranchesLogCmdIndex
|
i := self.allBranchesLogCmdIndex
|
||||||
self.allBranchesLogCmdIndex = uint8((int(i) + 1) % n)
|
|
||||||
|
|
||||||
return self.cmd.New(str.ToArgv(candidates[i])).DontLog()
|
return self.cmd.New(str.ToArgv(candidates[i])).DontLog()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *BranchCommands) RotateAllBranchesLogIdx() {
|
||||||
|
n := len(self.allBranchesLogCandidates())
|
||||||
|
i := self.allBranchesLogCmdIndex
|
||||||
|
self.allBranchesLogCmdIndex = uint8((int(i) + 1) % n)
|
||||||
|
}
|
||||||
|
|
||||||
func (self *BranchCommands) IsBranchMerged(branch *models.Branch, mainBranches *MainBranches) (bool, error) {
|
func (self *BranchCommands) IsBranchMerged(branch *models.Branch, mainBranches *MainBranches) (bool, error) {
|
||||||
branchesToCheckAgainst := []string{"HEAD"}
|
branchesToCheckAgainst := []string{"HEAD"}
|
||||||
if branch.RemoteBranchStoredLocally() {
|
if branch.RemoteBranchStoredLocally() {
|
||||||
|
@ -60,7 +60,7 @@ func (self *StatusController) GetKeybindings(opts types.KeybindingsOpts) []*type
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: opts.GetKey(opts.Config.Status.AllBranchesLogGraph),
|
Key: opts.GetKey(opts.Config.Status.AllBranchesLogGraph),
|
||||||
Handler: func() error { self.showAllBranchLogs(); return nil },
|
Handler: func() error { self.switchToOrRotateAllBranchesLogs(); return nil },
|
||||||
Description: self.c.Tr.AllBranchesLogGraph,
|
Description: self.c.Tr.AllBranchesLogGraph,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -190,6 +190,18 @@ func (self *StatusController) showAllBranchLogs() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Switches to the all branches view, or, if already on that view,
|
||||||
|
// rotates to the next command in the list, and then renders it.
|
||||||
|
func (self *StatusController) switchToOrRotateAllBranchesLogs() {
|
||||||
|
// A bit of a hack to ensure we only rotate to the next branch log command
|
||||||
|
// if we currently are looking at a branch log. Otherwise, we should just show
|
||||||
|
// the current index (if we are coming from the dashboard).
|
||||||
|
if self.c.Views().Main.Title == self.c.Tr.LogTitle {
|
||||||
|
self.c.Git().Branch.RotateAllBranchesLogIdx()
|
||||||
|
}
|
||||||
|
self.showAllBranchLogs()
|
||||||
|
}
|
||||||
|
|
||||||
func (self *StatusController) showDashboard() {
|
func (self *StatusController) showDashboard() {
|
||||||
versionStr := "master"
|
versionStr := "master"
|
||||||
version, err := types.ParseVersionNumber(self.c.GetConfig().GetVersion())
|
version, err := types.ParseVersionNumber(self.c.GetConfig().GetVersion())
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
package status
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
|
)
|
||||||
|
|
||||||
|
var LogCmdStatusPanelAllBranchesLog = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
|
Description: "Cycle between two different log commands in the Status view when it has status panel AllBranchesLog",
|
||||||
|
ExtraCmdArgs: []string{},
|
||||||
|
Skip: false,
|
||||||
|
SetupConfig: func(config *config.AppConfig) {
|
||||||
|
config.GetUserConfig().Git.AllBranchesLogCmds = []string{`echo "view1"`, `echo "view2"`}
|
||||||
|
config.GetUserConfig().Gui.StatusPanelView = "allBranchesLog"
|
||||||
|
},
|
||||||
|
SetupRepo: func(shell *Shell) {},
|
||||||
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
|
t.Views().Status().
|
||||||
|
Focus()
|
||||||
|
t.Views().Main().Content(Contains("view1"))
|
||||||
|
|
||||||
|
// We head to the branches view and return
|
||||||
|
t.Views().Branches().
|
||||||
|
Focus()
|
||||||
|
t.Views().Status().
|
||||||
|
Focus()
|
||||||
|
|
||||||
|
t.Views().Main().Content(Contains("view1").DoesNotContain("view2"))
|
||||||
|
|
||||||
|
t.Views().Status().
|
||||||
|
Press(keys.Status.AllBranchesLogGraph)
|
||||||
|
t.Views().Main().Content(Contains("view2").DoesNotContain("view1"))
|
||||||
|
|
||||||
|
t.Views().Status().
|
||||||
|
Press(keys.Status.AllBranchesLogGraph)
|
||||||
|
t.Views().Main().Content(Contains("view1").DoesNotContain("view2"))
|
||||||
|
},
|
||||||
|
})
|
@ -360,6 +360,7 @@ var tests = []*components.IntegrationTest{
|
|||||||
status.ClickToFocus,
|
status.ClickToFocus,
|
||||||
status.ClickWorkingTreeStateToOpenRebaseOptionsMenu,
|
status.ClickWorkingTreeStateToOpenRebaseOptionsMenu,
|
||||||
status.LogCmd,
|
status.LogCmd,
|
||||||
|
status.LogCmdStatusPanelAllBranchesLog,
|
||||||
status.ShowDivergenceFromBaseBranch,
|
status.ShowDivergenceFromBaseBranch,
|
||||||
submodule.Add,
|
submodule.Add,
|
||||||
submodule.Enter,
|
submodule.Enter,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user