Codemirror keymap vim <Esc> not working
I am using the CodeMirror editor in my project. I used scripts /addon/display/fullscreen.jsand /keymap/vim.jstogether and declared an instance of CodeMirror as follows:
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
keyMap: "vim",
extraKeys: {
"F11": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
As shown, I displayed the Esc key to exit the full screen display. Now this key mapping overrides the "Esc" key mapping defined in the /keymap/vim.jsscript to change the mode from insertto visual.
I checked the script and found this function,
function handleEsc() {
if (key == '<Esc>') {
// Clear input state and get back to normal mode.
clearInputState(cm);
if (vim.visualMode) {
exitVisualMode(cm);
} else if (vim.insertMode) {
exitInsertMode(cm);
}
return true;
}
}
Now I think I need to change my ad to something like this,
extraKeys: {
"F11": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
if (cm.getOption("keyMap") == "vim"){
//Call handleEsc()
}
}
}
But I have no idea how to make it work. Any help would be greatly appreciated.
+4
2 answers