Add command autocompletion for toggle

This commit is contained in:
n-peugnet 2022-04-11 00:05:37 +02:00
parent a7562a068a
commit edaed2bf65
2 changed files with 14 additions and 0 deletions

View File

@ -56,3 +56,16 @@ func autocompleteFile(cmd *CommandAutocomplete) (completions []string, newText s
}
return
}
func autocompleteToggle(cmd *CommandAutocomplete) (completions []string, newText string) {
completions = make([]string, 0, len(toggleMsg))
for k := range toggleMsg {
if (strings.HasPrefix(k, cmd.RawArgs)) {
completions = append(completions, k)
}
}
if len(completions) == 1 {
newText = fmt.Sprintf("/%s %s", cmd.OrigCommand, completions[0])
}
return
}

View File

@ -122,6 +122,7 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor {
"import": autocompleteFile,
"export": autocompleteFile,
"export-room": autocompleteFile,
"toggle": autocompleteToggle,
},
commands: map[string]CommandHandler{
"unknown-command": cmdUnknownCommand,