From e799976b8a5678db6adf1273960eeef44bd701c9 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 15 Feb 2025 16:19:19 +0100 Subject: [PATCH] Extract a method CustomCommand.GetDescription We'll reuse it in the next commit. --- pkg/config/user_config.go | 8 ++++++++ pkg/gui/services/custom_commands/keybinding_creator.go | 7 +------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index a1bbe09a6..c4db37b54 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -640,6 +640,14 @@ type CustomCommand struct { After *CustomCommandAfterHook `yaml:"after"` } +func (c *CustomCommand) GetDescription() string { + if c.Description != "" { + return c.Description + } + + return c.Command +} + type CustomCommandPrompt struct { // One of: 'input' | 'menu' | 'confirm' | 'menuFromCommand' Type string `yaml:"type"` diff --git a/pkg/gui/services/custom_commands/keybinding_creator.go b/pkg/gui/services/custom_commands/keybinding_creator.go index 4e6f9d8c7..259954c17 100644 --- a/pkg/gui/services/custom_commands/keybinding_creator.go +++ b/pkg/gui/services/custom_commands/keybinding_creator.go @@ -34,18 +34,13 @@ func (self *KeybindingCreator) call(customCommand config.CustomCommand, handler return nil, err } - description := customCommand.Description - if description == "" { - description = customCommand.Command - } - return lo.Map(viewNames, func(viewName string, _ int) *types.Binding { return &types.Binding{ ViewName: viewName, Key: keybindings.GetKey(customCommand.Key), Modifier: gocui.ModNone, Handler: handler, - Description: description, + Description: customCommand.GetDescription(), } }), nil }