Skip to content

Retain index position of allBranchesLogCmd when toggling status panel #4556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ Note that this disregards the selection, the new branch is always created either
| `` u `` | Check for update | |
| `` <enter> `` | Switch to a recent repo | |
| `` a `` | Show/cycle all branch logs | |
| `` 0 `` | Focus main view | |

## Sub-commits

Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ Note that this disregards the selection, the new branch is always created either
| `` u `` | 更新を確認 | |
| `` <enter> `` | 最近使用したリポジトリに切り替え | |
| `` a `` | Show/cycle all branch logs | |
| `` 0 `` | Focus main view | |

## タグ

Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ Note that this disregards the selection, the new branch is always created either
| `` u `` | 업데이트 확인 | |
| `` <enter> `` | 최근에 사용한 저장소로 전환 | |
| `` a `` | Show/cycle all branch logs | |
| `` 0 `` | Focus main view | |

## 서브모듈

Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_nl.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ Note that this disregards the selection, the new branch is always created either
| `` u `` | Check voor updates | |
| `` <enter> `` | Wissel naar een recente repo | |
| `` a `` | Show/cycle all branch logs | |
| `` 0 `` | Focus main view | |

## Sub-commits

Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_pl.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ Note that this disregards the selection, the new branch is always created either
| `` u `` | Sprawdź aktualizacje | |
| `` <enter> `` | Przełącz na ostatnie repozytorium | |
| `` a `` | Show/cycle all branch logs | |
| `` 0 `` | Focus main view | |

## Sub-commity

Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_pt.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ Note that this disregards the selection, the new branch is always created either
| `` u `` | Verificar atualização | |
| `` <enter> `` | Mudar para um repositório recente | |
| `` a `` | Mostrar/ciclo todos os logs de filiais | |
| `` 0 `` | Focus main view | |

## Sub-commits

Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ Note that this disregards the selection, the new branch is always created either
| `` u `` | Проверить обновления | |
| `` <enter> `` | Переключиться на последний репозиторий | |
| `` a `` | Show/cycle all branch logs | |
| `` 0 `` | Focus main view | |

## Теги

Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ Note that this disregards the selection, the new branch is always created either
| `` u `` | 检查更新 | |
| `` <enter> `` | 切换到最近的仓库 | |
| `` a `` | Show/cycle all branch logs | |
| `` 0 `` | Focus main view | |

## 确认面板

Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ Note that this disregards the selection, the new branch is always created either
| `` u `` | 檢查更新 | |
| `` <enter> `` | 切換到最近使用的版本庫 | |
| `` a `` | Show/cycle all branch logs | |
| `` 0 `` | Focus main view | |

## 確認面板

Expand Down
21 changes: 16 additions & 5 deletions pkg/commands/git_commands/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,27 @@ func (self *BranchCommands) Merge(branchName string, opts MergeOpts) error {
return self.cmd.New(cmdArgs).Run()
}

func (self *BranchCommands) AllBranchesLogCmdObj() *oscommands.CmdObj {
// Only choose between non-empty, non-identical commands
candidates := lo.Uniq(lo.WithoutEmpty(self.UserConfig().Git.AllBranchesLogCmds))
// Only choose between non-empty, non-identical commands
func (self *BranchCommands) allBranchesLogCandidates() []string {
return lo.Uniq(lo.WithoutEmpty(self.UserConfig().Git.AllBranchesLogCmds))
}

n := len(candidates)
func (self *BranchCommands) CurrentAllBranchesLogCmdObj() *oscommands.CmdObj {
candidates := self.allBranchesLogCandidates()

i := self.allBranchesLogCmdIndex
return self.cmd.New(str.ToArgv(candidates[i])).DontLog()
}

func (self *BranchCommands) rotateAllBranchesIdx() {
n := len(self.allBranchesLogCandidates())
i := self.allBranchesLogCmdIndex
self.allBranchesLogCmdIndex = uint8((int(i) + 1) % n)
}

return self.cmd.New(str.ToArgv(candidates[i])).DontLog()
func (self *BranchCommands) RotateAllBranchesLogCmdObj() *oscommands.CmdObj {
self.rotateAllBranchesIdx()
return self.CurrentAllBranchesLogCmdObj()
}

func (self *BranchCommands) IsBranchMerged(branch *models.Branch, mainBranches *MainBranches) (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/git_commands/branch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func TestBranchGetAllBranchGraph(t *testing.T) {
"log", "--graph", "--all", "--color=always", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium",
}, "", nil)
instance := buildBranchCommands(commonDeps{runner: runner})
err := instance.AllBranchesLogCmdObj().Run()
err := instance.RotateAllBranchesLogCmdObj().Run()
assert.NoError(t, err)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/gui/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func (gui *Gui) resetHelpersAndControllers() {
}

for _, context := range []types.Context{
gui.State.Contexts.Status,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am in no way positive this is the correct way to register a context as focusable, when it has no particular behaviors that it needs besides search-ability.

I just saw this added in https://github.com/jesseduffield/lazygit/pull/4429/files#diff-451b1ef5904657beb9097bcb881b06951fa00d4339d317f67030f556f456012eR269-R282, and some basic manual testing makes it seem like I now have the 0 keybinding I would want and searching works.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is all we need. What happens here is that it attaches the SwitchToFocusedMainViewController to the context, which takes care of handling the 0 press; once the main view is focused, the MainViewController takes over and handles all the keybindings for scrolling, begin/end etc.

I don't agree with the commit message when it says "It only needs to be focused in order to search through it." Focusing is also useful for scrolling it, which of course isn't needed for the dashboard, but could be useful after pressing a (also without the rest of this branch).

gui.State.Contexts.Files,
gui.State.Contexts.Branches,
gui.State.Contexts.RemoteBranches,
Expand Down
18 changes: 16 additions & 2 deletions pkg/gui/controllers/status_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (self *StatusController) GetKeybindings(opts types.KeybindingsOpts) []*type
},
{
Key: opts.GetKey(opts.Config.Status.AllBranchesLogGraph),
Handler: func() error { self.showAllBranchLogs(); return nil },
Handler: func() error { self.rotateAllBranchesLogs(); return nil },
Description: self.c.Tr.AllBranchesLogGraph,
},
}
Expand Down Expand Up @@ -178,7 +178,21 @@ func (self *StatusController) editConfig() error {
}

func (self *StatusController) showAllBranchLogs() {
cmdObj := self.c.Git().Branch.AllBranchesLogCmdObj()
cmdObj := self.c.Git().Branch.CurrentAllBranchesLogCmdObj()
task := types.NewRunPtyTask(cmdObj.GetCmd())

self.c.RenderToMainViews(types.RefreshMainOpts{
Pair: self.c.MainViewPairs().Normal,
Main: &types.ViewUpdateOpts{
Title: self.c.Tr.LogTitle,
Task: task,
},
})
}

// Switches to the next branch command and renders it onto the screen
func (self *StatusController) rotateAllBranchesLogs() {
cmdObj := self.c.Git().Branch.RotateAllBranchesLogCmdObj()
task := types.NewRunPtyTask(cmdObj.GetCmd())

self.c.RenderToMainViews(types.RefreshMainOpts{
Expand Down
6 changes: 3 additions & 3 deletions pkg/integration/tests/status/log_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ var LogCmd = NewIntegrationTest(NewIntegrationTestArgs{
t.Views().Status().
Focus().
Press(keys.Status.AllBranchesLogGraph)
t.Views().Main().Content(Contains("view1"))
t.Views().Main().Content(Contains("view2"))

t.Views().Status().
Focus().
Press(keys.Status.AllBranchesLogGraph)
t.Views().Main().Content(Contains("view2").DoesNotContain("view1"))
t.Views().Main().Content(Contains("view1").DoesNotContain("view2"))

t.Views().Status().
Focus().
Press(keys.Status.AllBranchesLogGraph)
t.Views().Main().Content(Contains("view1").DoesNotContain("view2"))
t.Views().Main().Content(Contains("view2").DoesNotContain("view1"))
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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"))

t.Views().Status().
Focus().
Press(keys.Status.AllBranchesLogGraph)
t.Views().Main().Content(Contains("view2").DoesNotContain("view1"))

t.Views().Status().
Focus().
Press(keys.Status.AllBranchesLogGraph)
t.Views().Main().Content(Contains("view1").DoesNotContain("view2"))
},
})
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ var tests = []*components.IntegrationTest{
status.ClickToFocus,
status.ClickWorkingTreeStateToOpenRebaseOptionsMenu,
status.LogCmd,
status.LogCmdStatusPanelAllBranchesLog,
status.ShowDivergenceFromBaseBranch,
submodule.Add,
submodule.Enter,
Expand Down
Loading