Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Give extraKeys a lower prec than addKeyMap keys, add bottom arg to ad…

…dKeyMap
  • Loading branch information...
commit 20ea151001909161cdd940571450b8c1426bc001 1 parent d8a583e
@marijnh marijnh authored
Showing with 15 additions and 13 deletions.
  1. +11 −9 doc/manual.html
  2. +3 −3 lib/codemirror.js
  3. +1 −1  test/test.js
View
20 doc/manual.html
@@ -834,16 +834,18 @@ <h3 id="api_configuration">Configuration methods</h3>
<dd>Retrieves the current value of the given option for this
editor instance.</dd>
- <dt id="addKeyMap"><code>cm.addKeyMap(map)</code></dt>
- <dd>Attach an additional <a href="#keymaps">keymap</a> to the editor. This is mostly
- useful for add-ons that need to register some key handlers
- without trampling on
+ <dt id="addKeyMap"><code>cm.addKeyMap(map, bottom)</code></dt>
+ <dd>Attach an additional <a href="#keymaps">keymap</a> to the
+ editor. This is mostly useful for add-ons that need to register
+ some key handlers without trampling on
the <a href="#option_extraKeys"><code>extraKeys</code></a>
- option. Maps added in this way have a lower precedence
- than <code>extraKeys</code>, a higher precedence than the
- base <a href="#option_keyMap"><code>keyMap</code></a>, and
- between them, the maps added earlier have a higher precedence
- than those added later.</dd>
+ option. Maps added in this way have a higher precedence than
+ the <code>extraKeys</code>
+ and <a href="#option_keyMap"><code>keyMap</code></a> options,
+ and between them, the maps added earlier have a lower precedence
+ than those added later, unless the <code>bottom</code> argument
+ was passed, in which case they end up below other keymaps added
+ with this method.</dd>
<dt id="removeKeyMap"><code>cm.removeKeyMap(map)</code></dt>
<dd>Disable a keymap added
with <a href="#addKeyMap"><code>addKeyMap</code></a>. Either
View
6 lib/codemirror.js
@@ -1925,8 +1925,8 @@ window.CodeMirror = (function() {
function allKeyMaps(cm) {
var maps = cm.state.keyMaps.slice(0);
+ if (cm.options.extraKeys) maps.push(cm.options.extraKeys);
maps.push(cm.options.keyMap);
- if (cm.options.extraKeys) maps.unshift(cm.options.extraKeys);
return maps;
}
@@ -2691,8 +2691,8 @@ window.CodeMirror = (function() {
getOption: function(option) {return this.options[option];},
getDoc: function() {return this.doc;},
- addKeyMap: function(map) {
- this.state.keyMaps.push(map);
+ addKeyMap: function(map, bottom) {
+ this.state.keyMaps[bottom ? "push" : "unshift"](map);
},
removeKeyMap: function(map) {
var maps = this.state.keyMaps;
View
2  test/test.js
@@ -1298,7 +1298,7 @@ testCM("addKeyMap", function(cm) {
sendKey(39);
eqPos(cm.getCursor(), Pos(0, 1));
eq(test, 1);
- cm.addKeyMap(map2);
+ cm.addKeyMap(map2, true);
sendKey(39);
eq(test, 2);
cm.removeKeyMap(map1);

0 comments on commit 20ea151

Please sign in to comment.
Something went wrong with that request. Please try again.