1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-03 00:57:52 +02:00

Fix focus issue when opening recent-repos menu at launch

I don't know why we were setting the initial context to CurrentSideContext
and not just CurrentContext in the first place. If there is no current context
in either case it'll default to the files context. So the only issue is if
we anticipated that some random context would be focused and we didn't want to
activate that. But I can't think of any situation where that would happen.
This commit is contained in:
Jesse Duffield
2023-06-07 17:41:17 +10:00
parent b6a31369da
commit c92e687d3b
6 changed files with 48 additions and 2 deletions

View File

@ -120,6 +120,11 @@ func NewApp(config config.AppConfigurer, common *common.Common) (*App, error) {
return app, err return app, err
} }
// used for testing purposes
if os.Getenv("SHOW_RECENT_REPOS") == "true" {
showRecentRepos = true
}
app.Gui, err = gui.NewGui(common, config, gitVersion, updater, showRecentRepos, dirName) app.Gui, err = gui.NewGui(common, config, gitVersion, updater, showRecentRepos, dirName)
if err != nil { if err != nil {
return app, err return app, err

View File

@ -179,7 +179,7 @@ func (gui *Gui) onInitialViewsCreationForRepo() error {
} }
} }
initialContext := gui.c.CurrentSideContext() initialContext := gui.c.CurrentContext()
if err := gui.c.ActivateContext(initialContext); err != nil { if err := gui.c.ActivateContext(initialContext); err != nil {
return err return err
} }

View File

@ -187,6 +187,11 @@ func getLazygitCommand(test *IntegrationTest, paths Paths, rootDir string, sandb
if sandbox { if sandbox {
cmdObj.AddEnvVars(fmt.Sprintf("%s=%s", SANDBOX_ENV_VAR, "true")) cmdObj.AddEnvVars(fmt.Sprintf("%s=%s", SANDBOX_ENV_VAR, "true"))
} }
if test.ExtraEnvVars() != nil {
for key, value := range test.ExtraEnvVars() {
cmdObj.AddEnvVars(fmt.Sprintf("%s=%s", key, value))
}
}
if keyPressDelay > 0 { if keyPressDelay > 0 {
cmdObj.AddEnvVars(fmt.Sprintf("KEY_PRESS_DELAY=%d", keyPressDelay)) cmdObj.AddEnvVars(fmt.Sprintf("KEY_PRESS_DELAY=%d", keyPressDelay))

View File

@ -23,6 +23,7 @@ type IntegrationTest struct {
name string name string
description string description string
extraCmdArgs []string extraCmdArgs []string
extraEnvVars map[string]string
skip bool skip bool
setupRepo func(shell *Shell) setupRepo func(shell *Shell)
setupConfig func(config *config.AppConfig) setupConfig func(config *config.AppConfig)
@ -47,6 +48,7 @@ type NewIntegrationTestArgs struct {
// additional args passed to lazygit // additional args passed to lazygit
ExtraCmdArgs []string ExtraCmdArgs []string
// for when a test is flakey // for when a test is flakey
ExtraEnvVars map[string]string
Skip bool Skip bool
// to run a test only on certain git versions // to run a test only on certain git versions
GitVersion GitVersionRestriction GitVersion GitVersionRestriction
@ -112,6 +114,7 @@ func NewIntegrationTest(args NewIntegrationTestArgs) *IntegrationTest {
name: name, name: name,
description: args.Description, description: args.Description,
extraCmdArgs: args.ExtraCmdArgs, extraCmdArgs: args.ExtraCmdArgs,
extraEnvVars: args.ExtraEnvVars,
skip: args.Skip, skip: args.Skip,
setupRepo: args.SetupRepo, setupRepo: args.SetupRepo,
setupConfig: args.SetupConfig, setupConfig: args.SetupConfig,
@ -132,6 +135,10 @@ func (self *IntegrationTest) ExtraCmdArgs() []string {
return self.extraCmdArgs return self.extraCmdArgs
} }
func (self *IntegrationTest) ExtraEnvVars() map[string]string {
return self.extraEnvVars
}
func (self *IntegrationTest) Skip() bool { func (self *IntegrationTest) Skip() bool {
return self.skip return self.skip
} }

View File

@ -0,0 +1,28 @@
package misc
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
// Couldn't find an easy way to actually reproduce the situation of opening outside a repo,
// so I'm introducing a hacky env var to force lazygit to show the recent repos meu upon opening.
var RecentReposOnLaunch = NewIntegrationTest(NewIntegrationTestArgs{
Description: "When opening opening to a menu, focus is correctly given to the menu",
ExtraCmdArgs: []string{},
ExtraEnvVars: map[string]string{
"SHOW_RECENT_REPOS": "true",
},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.ExpectPopup().Menu().
Title(Equals("Recent repositories")).
Select(Contains("Cancel")).
Confirm()
t.Views().Files().IsFocused()
},
})

View File

@ -120,6 +120,7 @@ var tests = []*components.IntegrationTest{
interactive_rebase.SwapWithConflict, interactive_rebase.SwapWithConflict,
misc.ConfirmOnQuit, misc.ConfirmOnQuit,
misc.InitialOpen, misc.InitialOpen,
misc.RecentReposOnLaunch,
patch_building.Apply, patch_building.Apply,
patch_building.ApplyInReverse, patch_building.ApplyInReverse,
patch_building.ApplyInReverseWithConflict, patch_building.ApplyInReverseWithConflict,