commands: use SelectedAccountUiConfig instead of explicit nil check
Remove code duplication and provide completion even when acct is nil Signed-off-by: kt programs <ktprograms@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
a16bd05321
commit
a0fceb80b3
|
@ -24,11 +24,6 @@ func (Recover) Aliases() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Recover) Complete(aerc *widgets.Aerc, args []string) []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
|
// file name of temp file is hard-coded in the NewComposer() function
|
||||||
files, err := filepath.Glob(
|
files, err := filepath.Glob(
|
||||||
filepath.Join(os.TempDir(), "aerc-compose-*.eml"),
|
filepath.Join(os.TempDir(), "aerc-compose-*.eml"),
|
||||||
|
@ -50,11 +45,12 @@ func (Recover) Complete(aerc *widgets.Aerc, args []string) []string {
|
||||||
return files
|
return files
|
||||||
} else {
|
} else {
|
||||||
// only accepts one file to recover
|
// 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 {
|
} else {
|
||||||
// only accepts one file to recover
|
// only accepts one file to recover
|
||||||
return commands.FilterList(files, args[0], "", acct.UiConfig().FuzzyComplete)
|
return commands.FilterList(files, args[0], "", aerc.SelectedAccountUiConfig().FuzzyComplete)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,6 @@ func (Sort) Aliases() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Sort) Complete(aerc *widgets.Aerc, args []string) []string {
|
func (Sort) Complete(aerc *widgets.Aerc, args []string) []string {
|
||||||
acct := aerc.SelectedAccount()
|
|
||||||
if acct == nil {
|
|
||||||
return make([]string, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
supportedCriteria := []string{
|
supportedCriteria := []string{
|
||||||
"arrival",
|
"arrival",
|
||||||
"cc",
|
"cc",
|
||||||
|
@ -61,7 +56,7 @@ func (Sort) Complete(aerc *widgets.Aerc, args []string) []string {
|
||||||
}
|
}
|
||||||
// the last item is not complete
|
// the last item is not complete
|
||||||
completions = commands.FilterList(supportedCriteria, last, currentPrefix,
|
completions = commands.FilterList(supportedCriteria, last, currentPrefix,
|
||||||
acct.UiConfig().FuzzyComplete)
|
aerc.SelectedAccountUiConfig().FuzzyComplete)
|
||||||
return completions
|
return completions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,16 +20,11 @@ func (ChangeTab) Aliases() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ChangeTab) Complete(aerc *widgets.Aerc, args []string) []string {
|
func (ChangeTab) Complete(aerc *widgets.Aerc, args []string) []string {
|
||||||
acct := aerc.SelectedAccount()
|
|
||||||
if acct == nil {
|
|
||||||
return make([]string, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return aerc.TabNames()
|
return aerc.TabNames()
|
||||||
}
|
}
|
||||||
joinedArgs := strings.Join(args, " ")
|
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 {
|
func (ChangeTab) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
|
|
Loading…
Reference in New Issue