Merge pull request #114 from tophf/respect-user-extrakeys

Respect localStorage::editor.extraKeys user option
This commit is contained in:
Jason Barnabe 2015-05-14 14:47:41 -05:00
commit 28e34f2990

35
edit.js
View File

@ -159,20 +159,33 @@ function initCodeMirror() {
// "basic" keymap only has basic keys by design, so we skip it // "basic" keymap only has basic keys by design, so we skip it
CM.keyMap.sublime["Ctrl-G"] = "jumpToLine"; var extraKeysCommands = {};
CM.keyMap.emacsy["Ctrl-G"] = "jumpToLine"; if (userOptions && typeof userOptions.extraKeys == "object") {
CM.keyMap.pcDefault["Ctrl-J"] = "jumpToLine"; Object.keys(userOptions.extraKeys).forEach(function(key) {
CM.keyMap.macDefault["Cmd-J"] = "jumpToLine"; extraKeysCommands[userOptions.extraKeys[key]] = true;
});
CM.keyMap.pcDefault["Ctrl-Space"] = "autocomplete"; // will be used by "sublime" on PC via fallthrough }
CM.keyMap.macDefault["Alt-Space"] = "autocomplete"; // OSX uses Ctrl-Space and Cmd-Space for something else if (!extraKeysCommands.jumpToLine) {
CM.keyMap.emacsy["Alt-/"] = "autocomplete"; // copied from "emacs" keymap CM.keyMap.sublime["Ctrl-G"] = "jumpToLine";
// "vim" and "emacs" define their own autocomplete hotkeys CM.keyMap.emacsy["Ctrl-G"] = "jumpToLine";
CM.keyMap.pcDefault["Ctrl-J"] = "jumpToLine";
CM.keyMap.macDefault["Cmd-J"] = "jumpToLine";
}
if (!extraKeysCommands.autocomplete) {
CM.keyMap.pcDefault["Ctrl-Space"] = "autocomplete"; // will be used by "sublime" on PC via fallthrough
CM.keyMap.macDefault["Alt-Space"] = "autocomplete"; // OSX uses Ctrl-Space and Cmd-Space for something else
CM.keyMap.emacsy["Alt-/"] = "autocomplete"; // copied from "emacs" keymap
// "vim" and "emacs" define their own autocomplete hotkeys
}
if (isWindowsOS) { if (isWindowsOS) {
// "pcDefault" keymap on Windows should have F3/Shift-F3 // "pcDefault" keymap on Windows should have F3/Shift-F3
CM.keyMap.pcDefault["F3"] = "findNext"; if (!extraKeysCommands.findNext) {
CM.keyMap.pcDefault["Shift-F3"] = "findPrev"; CM.keyMap.pcDefault["F3"] = "findNext";
}
if (!extraKeysCommands.findPrev) {
CM.keyMap.pcDefault["Shift-F3"] = "findPrev";
}
// try to remap non-interceptable Ctrl-(Shift-)N/T/W hotkeys // try to remap non-interceptable Ctrl-(Shift-)N/T/W hotkeys
["N", "T", "W"].forEach(function(char) { ["N", "T", "W"].forEach(function(char) {