From 992f2bb38fe50e573c3db7dca3d6d186a41a93b1 Mon Sep 17 00:00:00 2001 From: tophf Date: Wed, 13 May 2015 23:49:18 +0300 Subject: [PATCH] Respect localStorage::editor.options.extraKeys user option --- edit.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/edit.js b/edit.js index 4859830a..2d03f168 100644 --- a/edit.js +++ b/edit.js @@ -159,20 +159,33 @@ function initCodeMirror() { // "basic" keymap only has basic keys by design, so we skip it - CM.keyMap.sublime["Ctrl-G"] = "jumpToLine"; - CM.keyMap.emacsy["Ctrl-G"] = "jumpToLine"; - CM.keyMap.pcDefault["Ctrl-J"] = "jumpToLine"; - CM.keyMap.macDefault["Cmd-J"] = "jumpToLine"; - - 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 + var extraKeysCommands = {}; + if (userOptions && typeof userOptions.extraKeys == "object") { + Object.keys(userOptions.extraKeys).forEach(function(key) { + extraKeysCommands[userOptions.extraKeys[key]] = true; + }); + } + if (!extraKeysCommands.jumpToLine) { + CM.keyMap.sublime["Ctrl-G"] = "jumpToLine"; + 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) { // "pcDefault" keymap on Windows should have F3/Shift-F3 - CM.keyMap.pcDefault["F3"] = "findNext"; - CM.keyMap.pcDefault["Shift-F3"] = "findPrev"; + if (!extraKeysCommands.findNext) { + 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 ["N", "T", "W"].forEach(function(char) {