From a694c458dd38d960189d4fc4b288e95ab692f404 Mon Sep 17 00:00:00 2001
From: Jesse Duffield <jessedduffield@gmail.com>
Date: Wed, 7 Jun 2023 10:15:49 +1000
Subject: [PATCH] Support authors and tags in custom command suggestions preset

---
 docs/Custom_Command_Keybindings.md                  |  2 +-
 pkg/gui/controllers/helpers/suggestions_helper.go   |  6 ++++++
 pkg/gui/services/custom_commands/handler_creator.go | 12 ++++++++----
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/docs/Custom_Command_Keybindings.md b/docs/Custom_Command_Keybindings.md
index 7565b9f3a..7cc3d035b 100644
--- a/docs/Custom_Command_Keybindings.md
+++ b/docs/Custom_Command_Keybindings.md
@@ -101,7 +101,7 @@ These fields are applicable to all prompts.
 The permitted suggestions fields are:
 | _field_ | _description_ | _required_ |
 |-----------------|----------------------|-|
-| preset | Uses built-in logic to obtain the suggestions. One of 'files', 'branches', 'remotes', 'remoteBranches', 'refs' | no |
+| preset | Uses built-in logic to obtain the suggestions. One of 'authors', 'branches', 'files', 'refs', 'remotes', 'remoteBranches', 'tags' | no |
 | command | Command to run such that each line in the output becomes a suggestion. Mutually exclusive with 'preset' field. | no |
 
 Here's an example of passing a preset:
diff --git a/pkg/gui/controllers/helpers/suggestions_helper.go b/pkg/gui/controllers/helpers/suggestions_helper.go
index 786ad7bfe..70fcf168a 100644
--- a/pkg/gui/controllers/helpers/suggestions_helper.go
+++ b/pkg/gui/controllers/helpers/suggestions_helper.go
@@ -157,6 +157,12 @@ func (self *SuggestionsHelper) getTagNames() []string {
 	})
 }
 
+func (self *SuggestionsHelper) GetTagsSuggestionsFunc() func(string) []*types.Suggestion {
+	tagNames := self.getTagNames()
+
+	return FuzzySearchFunc(tagNames)
+}
+
 func (self *SuggestionsHelper) GetRefsSuggestionsFunc() func(string) []*types.Suggestion {
 	remoteBranchNames := self.getRemoteBranchNames("/")
 	localBranchNames := self.getBranchNames()
diff --git a/pkg/gui/services/custom_commands/handler_creator.go b/pkg/gui/services/custom_commands/handler_creator.go
index 4dc6bc86e..404753edc 100644
--- a/pkg/gui/services/custom_commands/handler_creator.go
+++ b/pkg/gui/services/custom_commands/handler_creator.go
@@ -161,16 +161,20 @@ func (self *HandlerCreator) getCommandSuggestionsFn(command string) (func(string
 
 func (self *HandlerCreator) getPresetSuggestionsFn(preset string) (func(string) []*types.Suggestion, error) {
 	switch preset {
-	case "files":
-		return self.suggestionsHelper.GetFilePathSuggestionsFunc(), nil
+	case "authors":
+		return self.suggestionsHelper.GetAuthorsSuggestionsFunc(), nil
 	case "branches":
 		return self.suggestionsHelper.GetBranchNameSuggestionsFunc(), nil
+	case "files":
+		return self.suggestionsHelper.GetFilePathSuggestionsFunc(), nil
+	case "refs":
+		return self.suggestionsHelper.GetRefsSuggestionsFunc(), nil
 	case "remotes":
 		return self.suggestionsHelper.GetRemoteSuggestionsFunc(), nil
 	case "remoteBranches":
 		return self.suggestionsHelper.GetRemoteBranchesSuggestionsFunc("/"), nil
-	case "refs":
-		return self.suggestionsHelper.GetRefsSuggestionsFunc(), nil
+	case "tags":
+		return self.suggestionsHelper.GetTagsSuggestionsFunc(), nil
 	default:
 		return nil, fmt.Errorf("Unknown value for suggestionsPreset in custom command: %s. Valid values: files, branches, remotes, remoteBranches, refs", preset)
 	}