Skip to content

Commit

Permalink
Add disabled compat for user config (jesseduffield#2833)
Browse files Browse the repository at this point in the history
Treat <disabled> setting as equivalent to "null"
in keybindings user configs.
  • Loading branch information
karimkhaleel committed Oct 9, 2023
1 parent c39fafe commit d02deee
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
6 changes: 3 additions & 3 deletions docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ keybinding:
jumpToBlock: ['1', '2', '3', '4', '5'] # goto the Nth block / panel
nextMatch: 'n'
prevMatch: 'N'
optionMenu: null # show help menu
optionMenu: <disabled> # show help menu
optionMenu-alt1: '?' # show help menu
select: '<space>'
goInto: '<enter>'
Expand Down Expand Up @@ -462,12 +462,12 @@ Supported versions are "2" and "3". The deprecated config `showIcons` sets the v

For all possible keybinding options, check [Custom_Keybindings.md](https://github.com/jesseduffield/lazygit/blob/master/docs/keybindings/Custom_Keybindings.md)

You can disable certain key bindings by specifying `null`.
You can disable certain key bindings by specifying `<disabled>`.

```yaml
keybinding:
universal:
edit: null # disable 'edit file'
edit: <disabled> # disable 'edit file'
```

### Example Keybindings For Colemak Users
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ func GetDefaultConfig() *UserConfig {
NextMatch: "n",
PrevMatch: "N",
StartSearch: "/",
OptionMenu: "",
OptionMenu: "<disabled>",
OptionMenuAlt1: "?",
Select: "<space>",
GoInto: "<enter>",
Expand Down
4 changes: 3 additions & 1 deletion pkg/gui/keybindings/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ func LabelFromKey(key types.Key) string {

func GetKey(key string) types.Key {
runeCount := utf8.RuneCountInString(key)
if runeCount > 1 {
if key == "<disabled>" {
return nil
} else if runeCount > 1 {
binding, ok := keyByLabel[strings.ToLower(key)]
if !ok {
log.Fatalf("Unrecognized key %s for keybinding. For permitted values see %s", strings.ToLower(key), constants.Links.Docs.CustomKeybindings)
Expand Down
26 changes: 26 additions & 0 deletions pkg/integration/tests/misc/disabled_keybindings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package misc

import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var DisabledKeybindings = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Confirms You can set keybindings to blank to disable them",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Keybinding.Universal.PrevItem = "<disabled>"
config.UserConfig.Keybinding.Universal.NextItem = "<disabled>"
config.UserConfig.Keybinding.Universal.NextTab = "<up>"
config.UserConfig.Keybinding.Universal.PrevTab = "<down>"
},
SetupRepo: func(shell *Shell) {},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().
IsFocused().
Press("<up>")

t.Views().Worktrees().IsFocused()
},
})
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ var tests = []*components.IntegrationTest{
interactive_rebase.SwapWithConflict,
misc.ConfirmOnQuit,
misc.CopyToClipboard,
misc.DisabledKeybindings,
misc.InitialOpen,
misc.RecentReposOnLaunch,
patch_building.Apply,
Expand Down

0 comments on commit d02deee

Please sign in to comment.