1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-23 12:18:51 +02:00

Fix clicking in status side panel (#3547)

- **PR Description**

Clicking in the status side panel should activate it; also, clicking on
the repo name should bring up the recent repositories menu, and clicking
on the "(rebasing)" text should bring up the rebase options menu. All of
this was broken for a long time, since somewhere around the big
refactoring of March 2023. (The exact commit where it broke is hard to
bisect, since many of the commits in that area either don't compile or
crash at startup...)

I'm fixing this not because I think it's super important functionality
(nobody seems to have missed it for over a year), but because I have to
touch this code in another PR, and noticed that it wasn't working.

- **Please check if the PR fulfills these requirements**

* [x] Cheatsheets are up-to-date (run `go generate ./...`)
* [x] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
* [x] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide)
* [ ] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [ ] Docs (specifically `docs/Config.md`) have been updated if
necessary
* [x] You've read through your own file changes for silly mistakes etc
This commit is contained in:
Stefan Haller 2024-05-15 13:24:07 +02:00 committed by GitHub
commit 5558d873af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 93 additions and 9 deletions

View File

@ -75,6 +75,11 @@ func (self *StatusController) GetMouseKeybindings(opts types.KeybindingsOpts) []
Key: gocui.MouseLeft,
Handler: self.onClickMain,
},
{
ViewName: self.Context().GetViewName(),
Key: gocui.MouseLeft,
Handler: self.onClick,
},
}
}
@ -95,15 +100,11 @@ func (self *StatusController) GetOnRenderToMain() func() error {
}
}
func (self *StatusController) GetOnClick() func() error {
return self.onClick
}
func (self *StatusController) Context() types.Context {
return self.c.Contexts().Status
}
func (self *StatusController) onClick() error {
func (self *StatusController) onClick(opts gocui.ViewMouseBindingOpts) error {
// TODO: move into some abstraction (status is currently not a listViewContext where a lot of this code lives)
currentBranch := self.c.Helpers().Refs.GetCheckedOutRef()
if currentBranch == nil {
@ -115,21 +116,20 @@ func (self *StatusController) onClick() error {
return err
}
cx, _ := self.c.Views().Status.Cursor()
upstreamStatus := presentation.BranchStatus(currentBranch, types.ItemOperationNone, self.c.Tr, time.Now(), self.c.UserConfig)
repoName := self.c.Git().RepoPaths.RepoName()
workingTreeState := self.c.Git().Status.WorkingTreeState()
switch workingTreeState {
case enums.REBASE_MODE_REBASING, enums.REBASE_MODE_MERGING:
workingTreeStatus := fmt.Sprintf("(%s)", presentation.FormatWorkingTreeStateLower(self.c.Tr, workingTreeState))
if cursorInSubstring(cx, upstreamStatus+" ", workingTreeStatus) {
if cursorInSubstring(opts.X, upstreamStatus+" ", workingTreeStatus) {
return self.c.Helpers().MergeAndRebase.CreateRebaseOptionsMenu()
}
if cursorInSubstring(cx, upstreamStatus+" "+workingTreeStatus+" ", repoName) {
if cursorInSubstring(opts.X, upstreamStatus+" "+workingTreeStatus+" ", repoName) {
return self.c.Helpers().Repos.CreateRecentReposMenu()
}
default:
if cursorInSubstring(cx, upstreamStatus+" ", repoName) {
if cursorInSubstring(opts.X, upstreamStatus+" ", repoName) {
return self.c.Helpers().Repos.CreateRecentReposMenu()
}
}

View File

@ -0,0 +1,18 @@
package status
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var ClickRepoNameToOpenReposMenu = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Click on the repo name in the status side panel to open the recent repositories menu",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Status().Click(1, 0)
t.ExpectPopup().Menu().Title(Equals("Recent repositories"))
},
})

View File

@ -0,0 +1,35 @@
package status
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var ClickToFocus = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Click in the status side panel to activate it",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().Focus()
t.Views().Main().Lines(
Contains("No changed files"),
)
t.Views().Status().Click(0, 0)
t.Views().Status().IsFocused()
t.Views().Main().ContainsLines(
Contains(` _`),
Contains(` | | (_) |`),
Contains(` | | __ _ _____ _ __ _ _| |_`),
Contains(" | |/ _` |_ / | | |/ _` | | __|"),
Contains(` | | (_| |/ /| |_| | (_| | | |_`),
Contains(` |_|\__,_/___|\__, |\__, |_|\__|`),
Contains(` __/ | __/ |`),
Contains(` |___/ |___/`),
Contains(``),
Contains(`Copyright `),
)
},
})

View File

@ -0,0 +1,27 @@
package status
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var ClickWorkingTreeStateToOpenRebaseOptionsMenu = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Click on the working tree state in the status side panel to open the rebase options menu",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateNCommits(2)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
Press(keys.Universal.Edit)
t.Views().Status().
Content(Contains("(rebasing) repo")).
Click(1, 0)
t.ExpectPopup().Menu().Title(Equals("Rebase options"))
},
})

View File

@ -23,6 +23,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/integration/tests/reflog"
"github.com/jesseduffield/lazygit/pkg/integration/tests/staging"
"github.com/jesseduffield/lazygit/pkg/integration/tests/stash"
"github.com/jesseduffield/lazygit/pkg/integration/tests/status"
"github.com/jesseduffield/lazygit/pkg/integration/tests/submodule"
"github.com/jesseduffield/lazygit/pkg/integration/tests/sync"
"github.com/jesseduffield/lazygit/pkg/integration/tests/tag"
@ -257,6 +258,9 @@ var tests = []*components.IntegrationTest{
stash.StashIncludingUntrackedFiles,
stash.StashStaged,
stash.StashUnstaged,
status.ClickRepoNameToOpenReposMenu,
status.ClickToFocus,
status.ClickWorkingTreeStateToOpenRebaseOptionsMenu,
submodule.Add,
submodule.Enter,
submodule.EnterNested,