Add support for binding command and command-edit
This commit is contained in:
parent
4bdf788091
commit
ab37e6ad6c
2 changed files with 18 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
|||
package action
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zyedidia/micro/cmd/micro/buffer"
|
||||
|
@ -24,7 +25,15 @@ func init() {
|
|||
|
||||
// BufMapKey maps a key event to an action
|
||||
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
|
||||
BufKeyBindings[k] = f
|
||||
} else {
|
||||
|
@ -36,14 +45,9 @@ func BufMapKey(k Event, action string) {
|
|||
func BufMapMouse(k MouseEvent, action string) {
|
||||
if f, ok := BufMouseActions[action]; ok {
|
||||
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 {
|
||||
screen.TermMessage("Error:", action, "does not exist")
|
||||
delete(BufMouseBindings, k)
|
||||
BufMapKey(k, action)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -539,9 +539,13 @@ func (h *BufPane) QuitCmd(args []string) {
|
|||
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) {
|
||||
h.Save()
|
||||
if len(args) == 0 {
|
||||
h.Save()
|
||||
} else {
|
||||
h.Buf.SaveAs(args[0])
|
||||
}
|
||||
}
|
||||
|
||||
// ReplaceCmd runs search and replace
|
||||
|
|
Loading…
Reference in a new issue