Add support for binding command and command-edit

This commit is contained in:
Zachary Yedidia
2019-01-19 17:14:51 -05:00
parent 4bdf788091
commit ab37e6ad6c
2 changed files with 18 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
package action package action
import ( import (
"strings"
"time" "time"
"github.com/zyedidia/micro/cmd/micro/buffer" "github.com/zyedidia/micro/cmd/micro/buffer"
@@ -24,7 +25,15 @@ func init() {
// BufMapKey maps a key event to an action // BufMapKey maps a key event to an action
func BufMapKey(k Event, action string) { func BufMapKey(k Event, action string) {
if f, ok := BufKeyActions[action]; ok { if strings.HasPrefix(action, "command:") {
action = strings.SplitN(action, ":", 2)[1]
BufKeyStrings[k] = action
BufKeyBindings[k] = CommandAction(action)
} else if strings.HasPrefix(action, "command-edit:") {
action = strings.SplitN(action, ":", 2)[1]
BufKeyStrings[k] = action
BufKeyBindings[k] = CommandEditAction(action)
} else if f, ok := BufKeyActions[action]; ok {
BufKeyStrings[k] = action BufKeyStrings[k] = action
BufKeyBindings[k] = f BufKeyBindings[k] = f
} else { } else {
@@ -36,14 +45,9 @@ func BufMapKey(k Event, action string) {
func BufMapMouse(k MouseEvent, action string) { func BufMapMouse(k MouseEvent, action string) {
if f, ok := BufMouseActions[action]; ok { if f, ok := BufMouseActions[action]; ok {
BufMouseBindings[k] = f BufMouseBindings[k] = f
} else if f, ok := BufKeyActions[action]; ok {
// allowed to map mouse buttons to key actions
BufKeyStrings[k] = action
BufKeyBindings[k] = f
// ensure we don't double bind a key
delete(BufMouseBindings, k)
} else { } else {
screen.TermMessage("Error:", action, "does not exist") delete(BufMouseBindings, k)
BufMapKey(k, action)
} }
} }

View File

@@ -539,9 +539,13 @@ func (h *BufPane) QuitCmd(args []string) {
h.Quit() h.Quit()
} }
// SaveCmd saves the buffer in the main view // SaveCmd saves the buffer optionally with an argument file name
func (h *BufPane) SaveCmd(args []string) { func (h *BufPane) SaveCmd(args []string) {
h.Save() if len(args) == 0 {
h.Save()
} else {
h.Buf.SaveAs(args[0])
}
} }
// ReplaceCmd runs search and replace // ReplaceCmd runs search and replace