From 65b69016b009baa2bc64310f296726c8e872ac35 Mon Sep 17 00:00:00 2001 From: mokashang Date: Tue, 26 May 2026 09:19:41 -0700 Subject: [PATCH] Allow rebinding the confirm key for search and prompt The confirm action for the search/filter prompt and for text input prompts (e.g. naming a stash or a new branch) was hard-coded to in #4860, on the assumption that these wouldn't be remapped. That assumption turned out to be wrong: users who rebind universal.confirm to a key such as could no longer confirm these two prompts. Add ConfirmSearch and ConfirmPrompt keybindings, following the existing pattern of context-specific confirm keys (confirmMenu, confirmSuggestion, confirmInEditor). Both default to , so behaviour is unchanged for users who don't remap them. Fixes #5510 --- docs-master/Config.md | 8 +++ pkg/config/user_config.go | 8 ++- pkg/gui/controllers/prompt_controller.go | 2 +- .../controllers/search_prompt_controller.go | 3 +- .../rebind_confirm_search_and_prompt.go | 61 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + schema-master/config.json | 30 +++++++++ 7 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 pkg/integration/tests/config/rebind_confirm_search_and_prompt.go diff --git a/docs-master/Config.md b/docs-master/Config.md index 9f79218217f..6a2958bd97b 100644 --- a/docs-master/Config.md +++ b/docs-master/Config.md @@ -644,6 +644,14 @@ keybinding: confirmMenu: confirmSuggestion: + # Key for confirming the search/filter prompt (the one opened with + # `startSearch`). + confirmSearch: + + # Key for confirming a text input prompt (e.g. when naming a stash or a new + # branch). + confirmPrompt: + # on Mac confirmInEditor: [, ] remove: d diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index cac87ec9157..8422b261d55 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -474,7 +474,11 @@ type KeybindingUniversalConfig struct { Confirm Keybinding `yaml:"confirm"` ConfirmMenu Keybinding `yaml:"confirmMenu"` ConfirmSuggestion Keybinding `yaml:"confirmSuggestion"` - ConfirmInEditor Keybinding `yaml:"confirmInEditor"` // on Mac + // Key for confirming the search/filter prompt (the one opened with `startSearch`). + ConfirmSearch Keybinding `yaml:"confirmSearch"` + // Key for confirming a text input prompt (e.g. when naming a stash or a new branch). + ConfirmPrompt Keybinding `yaml:"confirmPrompt"` + ConfirmInEditor Keybinding `yaml:"confirmInEditor"` // on Mac // Deprecated: add the key to `confirmInEditor` instead. ConfirmInEditorAlt Keybinding `yaml:"confirmInEditor-alt"` Remove Keybinding `yaml:"remove"` @@ -986,6 +990,8 @@ func GetDefaultConfigForPlatform(platform string) *UserConfig { Confirm: Keybinding{""}, ConfirmMenu: Keybinding{""}, ConfirmSuggestion: Keybinding{""}, + ConfirmSearch: Keybinding{""}, + ConfirmPrompt: Keybinding{""}, ConfirmInEditor: Keybinding{platformKeyBinding(platform, map[string]string{"darwin": ""}, "")}, ConfirmInEditorAlt: Keybinding{""}, Remove: Keybinding{"d"}, diff --git a/pkg/gui/controllers/prompt_controller.go b/pkg/gui/controllers/prompt_controller.go index abcf73ef5b5..c5126b4a1f3 100644 --- a/pkg/gui/controllers/prompt_controller.go +++ b/pkg/gui/controllers/prompt_controller.go @@ -27,7 +27,7 @@ func NewPromptController( func (self *PromptController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { bindings := []*types.Binding{ { - Keys: []gocui.Key{gocui.NewKeyName(gocui.KeyEnter)}, + Keys: opts.GetKeys(opts.Config.Universal.ConfirmPrompt), Handler: func() error { return self.context().State.OnConfirm() }, Description: self.c.Tr.Confirm, DisplayOnScreen: true, diff --git a/pkg/gui/controllers/search_prompt_controller.go b/pkg/gui/controllers/search_prompt_controller.go index 1ce02abf021..30494444ebc 100644 --- a/pkg/gui/controllers/search_prompt_controller.go +++ b/pkg/gui/controllers/search_prompt_controller.go @@ -1,7 +1,6 @@ package controllers import ( - "github.com/jesseduffield/lazygit/pkg/gocui" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -24,7 +23,7 @@ func NewSearchPromptController( func (self *SearchPromptController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { return []*types.Binding{ { - Keys: []gocui.Key{gocui.NewKeyName(gocui.KeyEnter)}, + Keys: opts.GetKeys(opts.Config.Universal.ConfirmSearch), Handler: self.confirm, }, { diff --git a/pkg/integration/tests/config/rebind_confirm_search_and_prompt.go b/pkg/integration/tests/config/rebind_confirm_search_and_prompt.go new file mode 100644 index 00000000000..5120b0f19d4 --- /dev/null +++ b/pkg/integration/tests/config/rebind_confirm_search_and_prompt.go @@ -0,0 +1,61 @@ +package config + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var RebindConfirmSearchAndPrompt = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Confirm a search and a text prompt using a rebound confirm keybinding", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(cfg *config.AppConfig) { + // The search and prompt confirm keys used to be hard-coded to , + // so they couldn't be rebound like the other confirm keybindings. + cfg.GetUserConfig().Keybinding.Universal.ConfirmSearch = []string{""} + cfg.GetUserConfig().Keybinding.Universal.ConfirmPrompt = []string{""} + }, + SetupRepo: func(shell *Shell) { + shell.NewBranch("branch") + shell.EmptyCommit("one") + shell.EmptyCommit("two") + shell.EmptyCommit("three") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + // Confirming a search with the rebound key works. + t.Views().Commits(). + Focus(). + Lines( + Contains("three").IsSelected(), + Contains("two"), + Contains("one"), + ). + Press(keys.Universal.StartSearch). + Tap(func() { + t.ExpectSearch(). + Type("two") + + t.GlobalPress(keys.Universal.ConfirmSearch) + + t.Views().Search().IsVisible().Content(Contains("matches for 'two' (1 of 1)")) + }). + Lines( + Contains("three"), + Contains("two").IsSelected(), + Contains("one"), + ) + + // Confirming a text input prompt with the rebound key works. + t.Views().Branches(). + Focus(). + Press(keys.Universal.New) + + t.ExpectPopup().Prompt(). + Title(Contains("New branch name")). + Type("new-branch") + + t.GlobalPress(keys.Universal.ConfirmPrompt) + + t.Git().CurrentBranchName("new-branch") + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index aea37515b6d..1b543251fd2 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -160,6 +160,7 @@ var tests = []*components.IntegrationTest{ commit.Unstaged, config.CustomCommandsInPerRepoConfig, config.NegativeRefspec, + config.RebindConfirmSearchAndPrompt, config.RemoteNamedStar, conflicts.Filter, conflicts.MergeFileBoth, diff --git a/schema-master/config.json b/schema-master/config.json index 2e968ba8f95..4393a6071d5 100644 --- a/schema-master/config.json +++ b/schema-master/config.json @@ -2786,6 +2786,36 @@ ], "default": "\u003center\u003e" }, + "confirmSearch": { + "oneOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + } + ], + "description": "Key for confirming the search/filter prompt (the one opened with `startSearch`).", + "default": "\u003center\u003e" + }, + "confirmPrompt": { + "oneOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "type": "array" + } + ], + "description": "Key for confirming a text input prompt (e.g. when naming a stash or a new branch).", + "default": "\u003center\u003e" + }, "confirmInEditor": { "oneOf": [ {