From e1b341e174ef2dcb5b0abb4eead81397bee076cd Mon Sep 17 00:00:00 2001 From: Abhishek Keshri Date: Sat, 28 Oct 2023 20:19:01 +0530 Subject: [PATCH] Make keybindings for the "Amend attribute" menu configurable --- docs/Config.md | 4 +++ pkg/config/user_config.go | 34 +++++++++++++------ .../controllers/local_commits_controller.go | 7 ++-- schema/config.json | 18 ++++++++++ 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/docs/Config.md b/docs/Config.md index 383a059cd..676be2173 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -279,6 +279,10 @@ keybinding: bulkMenu: 'b' commitMessage: switchToEditor: '' + amendAttribute: + addCoAuthor: 'c' + resetAuthor: 'a' + setAuthor: 'A' ``` ## Platform Defaults diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 6a4efe78a..6045edbe8 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -281,17 +281,18 @@ type UpdateConfig struct { } type KeybindingConfig struct { - Universal KeybindingUniversalConfig `yaml:"universal"` - Status KeybindingStatusConfig `yaml:"status"` - Files KeybindingFilesConfig `yaml:"files"` - Branches KeybindingBranchesConfig `yaml:"branches"` - Worktrees KeybindingWorktreesConfig `yaml:"worktrees"` - Commits KeybindingCommitsConfig `yaml:"commits"` - Stash KeybindingStashConfig `yaml:"stash"` - CommitFiles KeybindingCommitFilesConfig `yaml:"commitFiles"` - Main KeybindingMainConfig `yaml:"main"` - Submodules KeybindingSubmodulesConfig `yaml:"submodules"` - CommitMessage KeybindingCommitMessageConfig `yaml:"commitMessage"` + Universal KeybindingUniversalConfig `yaml:"universal"` + Status KeybindingStatusConfig `yaml:"status"` + Files KeybindingFilesConfig `yaml:"files"` + Branches KeybindingBranchesConfig `yaml:"branches"` + Worktrees KeybindingWorktreesConfig `yaml:"worktrees"` + Commits KeybindingCommitsConfig `yaml:"commits"` + AmendAttribute KeybindingAmendAttributeConfig `yaml:"amendAttribute"` + Stash KeybindingStashConfig `yaml:"stash"` + CommitFiles KeybindingCommitFilesConfig `yaml:"commitFiles"` + Main KeybindingMainConfig `yaml:"main"` + Submodules KeybindingSubmodulesConfig `yaml:"submodules"` + CommitMessage KeybindingCommitMessageConfig `yaml:"commitMessage"` } // damn looks like we have some inconsistencies here with -alt and -alt1 @@ -440,6 +441,12 @@ type KeybindingCommitsConfig struct { StartInteractiveRebase string `yaml:"startInteractiveRebase"` } +type KeybindingAmendAttributeConfig struct { + ResetAuthor string `yaml:"resetAuthor"` + SetAuthor string `yaml:"setAuthor"` + AddCoAuthor string `yaml:"addCoAuthor"` +} + type KeybindingStashConfig struct { PopStash string `yaml:"popStash"` RenameStash string `yaml:"renameStash"` @@ -836,6 +843,11 @@ func GetDefaultConfig() *UserConfig { ViewBisectOptions: "b", StartInteractiveRebase: "i", }, + AmendAttribute: KeybindingAmendAttributeConfig{ + ResetAuthor: "a", + SetAuthor: "A", + AddCoAuthor: "c", + }, Stash: KeybindingStashConfig{ PopStash: "g", RenameStash: "r", diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index d6cc26b5b..085504662 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -673,25 +673,26 @@ func (self *LocalCommitsController) canAmend(commit *models.Commit) *types.Disab } func (self *LocalCommitsController) amendAttribute(commit *models.Commit) error { + opts := self.c.KeybindingsOpts() return self.c.Menu(types.CreateMenuOptions{ Title: "Amend commit attribute", Items: []*types.MenuItem{ { Label: self.c.Tr.ResetAuthor, OnPress: self.resetAuthor, - Key: 'a', + Key: opts.GetKey(opts.Config.AmendAttribute.ResetAuthor), Tooltip: self.c.Tr.ResetAuthorTooltip, }, { Label: self.c.Tr.SetAuthor, OnPress: self.setAuthor, - Key: 'A', + Key: opts.GetKey(opts.Config.AmendAttribute.SetAuthor), Tooltip: self.c.Tr.SetAuthorTooltip, }, { Label: self.c.Tr.AddCoAuthor, OnPress: self.addCoAuthor, - Key: 'c', + Key: opts.GetKey(opts.Config.AmendAttribute.AddCoAuthor), Tooltip: self.c.Tr.AddCoAuthorTooltip, }, }, diff --git a/schema/config.json b/schema/config.json index 44d8e0cb4..bbb5ce61f 100644 --- a/schema/config.json +++ b/schema/config.json @@ -1163,6 +1163,24 @@ "additionalProperties": false, "type": "object" }, + "amendAttribute": { + "properties": { + "resetAuthor": { + "type": "string", + "default": "a" + }, + "setAuthor": { + "type": "string", + "default": "A" + }, + "addCoAuthor": { + "type": "string", + "default": "c" + } + }, + "additionalProperties": false, + "type": "object" + }, "stash": { "properties": { "popStash": {