package main
import (
- "encoding/json"
"io/ioutil"
"os"
"strings"
+ "github.com/yosuke-furukawa/json5/encoding/json5"
"github.com/zyedidia/tcell"
)
-var bindings map[Key][]func(*View) bool
+var bindings map[Key][]func(*View, bool) bool
var helpBinding string
-var bindingActions = map[string]func(*View) bool{
+var bindingActions = map[string]func(*View, bool) bool{
"CursorUp": (*View).CursorUp,
"CursorDown": (*View).CursorDown,
"CursorPageUp": (*View).CursorPageUp,
"DeleteWordLeft": (*View).DeleteWordLeft,
"SelectToStartOfLine": (*View).SelectToStartOfLine,
"SelectToEndOfLine": (*View).SelectToEndOfLine,
- "InsertEnter": (*View).InsertEnter,
+ "InsertNewline": (*View).InsertNewline,
"InsertSpace": (*View).InsertSpace,
"Backspace": (*View).Backspace,
"Delete": (*View).Delete,
"Find": (*View).Find,
"FindNext": (*View).FindNext,
"FindPrevious": (*View).FindPrevious,
+ "Center": (*View).Center,
"Undo": (*View).Undo,
"Redo": (*View).Redo,
"Copy": (*View).Copy,
"CutLine": (*View).CutLine,
"DuplicateLine": (*View).DuplicateLine,
"DeleteLine": (*View).DeleteLine,
+ "IndentSelection": (*View).IndentSelection,
+ "OutdentSelection": (*View).OutdentSelection,
"Paste": (*View).Paste,
+ "PastePrimary": (*View).PastePrimary,
"SelectAll": (*View).SelectAll,
"OpenFile": (*View).OpenFile,
"Start": (*View).Start,
"ShellMode": (*View).ShellMode,
"CommandMode": (*View).CommandMode,
"Quit": (*View).Quit,
+ "QuitAll": (*View).QuitAll,
"AddTab": (*View).AddTab,
"PreviousTab": (*View).PreviousTab,
"NextTab": (*View).NextTab,
"NextSplit": (*View).NextSplit,
"PreviousSplit": (*View).PreviousSplit,
+ "ToggleMacro": (*View).ToggleMacro,
+ "PlayMacro": (*View).PlayMacro,
+
+ // This was changed to InsertNewline but I don't want to break backwards compatibility
+ "InsertEnter": (*View).InsertNewline,
}
var bindingKeys = map[string]tcell.Key{
// InitBindings initializes the keybindings for micro
func InitBindings() {
- bindings = make(map[Key][]func(*View) bool)
+ bindings = make(map[Key][]func(*View, bool) bool)
var parsed map[string]string
defaults := DefaultBindings()
return
}
- err = json.Unmarshal(input, &parsed)
+ err = json5.Unmarshal(input, &parsed)
if err != nil {
TermMessage("Error reading bindings.json:", err.Error())
}
}
// findAction will find 'action' using string 'v'
-func findAction(v string) (action func(*View) bool) {
+func findAction(v string) (action func(*View, bool) bool) {
action, ok := bindingActions[v]
if !ok {
// If the user seems to be binding a function that doesn't exist
}
actionNames := strings.Split(v, ",")
- actions := make([]func(*View) bool, 0, len(actionNames))
+ actions := make([]func(*View, bool) bool, 0, len(actionNames))
for _, actionName := range actionNames {
actions = append(actions, findAction(actionName))
}
"CtrlDown": "CursorEnd",
"CtrlShiftUp": "SelectToStart",
"CtrlShiftDown": "SelectToEnd",
- "Enter": "InsertEnter",
+ "Enter": "InsertNewline",
"Space": "InsertSpace",
"Backspace": "Backspace",
"Backspace2": "Backspace",
"Alt-Backspace": "DeleteWordLeft",
"Alt-Backspace2": "DeleteWordLeft",
- "Tab": "InsertTab",
+ "Tab": "IndentSelection,InsertTab",
+ "Backtab": "OutdentSelection",
"CtrlO": "OpenFile",
"CtrlS": "Save",
"CtrlF": "Find",
"CtrlT": "AddTab",
"CtrlRightSq": "PreviousTab",
"CtrlBackslash": "NextTab",
- "Home": "Start",
- "End": "End",
+ "Home": "StartOfLine",
+ "End": "EndOfLine",
+ "CtrlHome": "CursorStart",
+ "CtrlEnd": "CursorEnd",
"PageUp": "CursorPageUp",
"PageDown": "CursorPageDown",
"CtrlG": "ToggleHelp",
"CtrlQ": "Quit",
"CtrlE": "CommandMode",
"CtrlW": "NextSplit",
+ "CtrlU": "ToggleMacro",
+ "CtrlJ": "PlayMacro",
// Emacs-style keybindings
"Alt-f": "WordRight",