From a0fceb80b3ac036326a3af20eb2a05bbe215be64 Mon Sep 17 00:00:00 2001 From: kt programs Date: Tue, 15 Mar 2022 09:55:51 +0800 Subject: commands: use SelectedAccountUiConfig instead of explicit nil check Remove code duplication and provide completion even when acct is nil Signed-off-by: kt programs Acked-by: Robin Jarry --- commands/account/recover.go | 10 +++------- commands/account/sort.go | 7 +------ commands/ct.go | 7 +------ 3 files changed, 5 insertions(+), 19 deletions(-) (limited to 'commands') diff --git a/commands/account/recover.go b/commands/account/recover.go index 855d984..8158af6 100644 --- a/commands/account/recover.go +++ b/commands/account/recover.go @@ -24,11 +24,6 @@ func (Recover) Aliases() []string { } func (Recover) Complete(aerc *widgets.Aerc, args []string) []string { - acct := aerc.SelectedAccount() - if acct == nil { - return make([]string, 0) - } - // file name of temp file is hard-coded in the NewComposer() function files, err := filepath.Glob( filepath.Join(os.TempDir(), "aerc-compose-*.eml"), @@ -50,11 +45,12 @@ func (Recover) Complete(aerc *widgets.Aerc, args []string) []string { return files } else { // only accepts one file to recover - return commands.FilterList(files, args[1], args[0]+" ", acct.UiConfig().FuzzyComplete) + return commands.FilterList(files, args[1], args[0]+" ", + aerc.SelectedAccountUiConfig().FuzzyComplete) } } else { // only accepts one file to recover - return commands.FilterList(files, args[0], "", acct.UiConfig().FuzzyComplete) + return commands.FilterList(files, args[0], "", aerc.SelectedAccountUiConfig().FuzzyComplete) } } diff --git a/commands/account/sort.go b/commands/account/sort.go index 15ecbc0..ad1a402 100644 --- a/commands/account/sort.go +++ b/commands/account/sort.go @@ -20,11 +20,6 @@ func (Sort) Aliases() []string { } func (Sort) Complete(aerc *widgets.Aerc, args []string) []string { - acct := aerc.SelectedAccount() - if acct == nil { - return make([]string, 0) - } - supportedCriteria := []string{ "arrival", "cc", @@ -61,7 +56,7 @@ func (Sort) Complete(aerc *widgets.Aerc, args []string) []string { } // the last item is not complete completions = commands.FilterList(supportedCriteria, last, currentPrefix, - acct.UiConfig().FuzzyComplete) + aerc.SelectedAccountUiConfig().FuzzyComplete) return completions } diff --git a/commands/ct.go b/commands/ct.go index f5f2cca..092d973 100644 --- a/commands/ct.go +++ b/commands/ct.go @@ -20,16 +20,11 @@ func (ChangeTab) Aliases() []string { } func (ChangeTab) Complete(aerc *widgets.Aerc, args []string) []string { - acct := aerc.SelectedAccount() - if acct == nil { - return make([]string, 0) - } - if len(args) == 0 { return aerc.TabNames() } joinedArgs := strings.Join(args, " ") - return FilterList(aerc.TabNames(), joinedArgs, "", acct.UiConfig().FuzzyComplete) + return FilterList(aerc.TabNames(), joinedArgs, "", aerc.SelectedAccountUiConfig().FuzzyComplete) } func (ChangeTab) Execute(aerc *widgets.Aerc, args []string) error { -- cgit v1.2.3