More command binding

Now can bind editable commands with `command-edit:`

Ref #974
This commit is contained in:
Zachary Yedidia
2018-01-02 15:15:28 -05:00
parent 70616b335e
commit a4ae7a1e11
4 changed files with 44 additions and 4 deletions

View File

@@ -479,6 +479,9 @@ func BindKey(k, v string) {
} else if strings.HasPrefix(actionName, "command:") {
cmd := strings.SplitN(actionName, ":", 2)[1]
actions = append(actions, CommandAction(cmd))
} else if strings.HasPrefix(actionName, "command-edit:") {
cmd := strings.SplitN(actionName, ":", 2)[1]
actions = append(actions, CommandEditAction(cmd))
} else {
actions = append(actions, findAction(actionName))
}

View File

@@ -120,6 +120,16 @@ func DefaultCommands() map[string]StrCommand {
}
}
func CommandEditAction(prompt string) func(*View, bool) bool {
return func(v *View, usePlugin bool) bool {
input, canceled := messenger.Prompt("> ", prompt, "Command", CommandCompletion)
if !canceled {
HandleCommand(input)
}
return false
}
}
func CommandAction(cmd string) func(*View, bool) bool {
return func(v *View, usePlugin bool) bool {
HandleCommand(cmd)

File diff suppressed because one or more lines are too long