Skip to content

Commit

Permalink
Allow the 'next' property of a keymap to be a function
Browse files Browse the repository at this point in the history
It'll be called with the current instance as argument, and should
*always* return a string that refers to a keymap.

Experimental feature, not documented yet.
  • Loading branch information
marijnh committed Jan 9, 2012
1 parent 280c471 commit d6ca4d7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/codemirror.js
Expand Up @@ -444,8 +444,11 @@ var CodeMirror = (function() {
}
function handleKeyBinding(e) {
var name = keyNames[e.keyCode], next = keyMap[options.keyMap].auto, bound, dropShift;
function handleNext() {
return next.call ? next.call(null, instance) : next;
}
if (name == null || e.altGraphKey) {
if (next) options.keyMap = next;
if (next) options.keyMap = handleNext();
return null;
}
if (e.altKey) name = "Alt-" + name;
Expand All @@ -460,7 +463,7 @@ var CodeMirror = (function() {
if (commands.propertyIsEnumerable(bound)) bound = commands[bound];
else bound = null;
}
if (next && (bound || !isModifierKey(e))) options.keyMap = next;
if (next && (bound || !isModifierKey(e))) options.keyMap = handleNext();
if (!bound) return false;
if (dropShift) {
var prevShift = shiftSelecting;
Expand Down

0 comments on commit d6ca4d7

Please sign in to comment.