I use CodeMirror along with jQuery to highlight syntax highlighting in a PoC pet project. This is great until I realized that CodeMirror seems to capture the key events of clicking on the DOM in such a way that it stops working with global application hotkeys when I am currently printing a text area with CM support.
For simplicity, suppose I have the following listener on my page:
var hotkey = function (e) {
if (e.shiftKey) { alert('foo'); }
};
$(document).keypress(hotkey);
This will work everywhere on the page, unless I have a CM text area in focus.
To try to get around this, I tried using the CM parameter onKeyEvent, and also tried to normalize the object eventpassed in by the CM handler using the jQuery.Eventfollowing:
var cm = CodeMirror.fromTextArea(someTextArea, {
onKeyEvent : function (editor, event) {
hotkey($.Event(event));
}
});
It successfully receives events keydownand keypressover my handler hotkey.
The problem is that the "normalized" object event, apparently, is not normalized enough, since the link to something trivial, since it returns e.shiftKeyin the area . (I get correctly as or , therefore, I know that I am passing an object .)hotkeyundefinede.typekeydownkeypressevent
Is there something that I am missing here, as a result of which my eventmissing properties are missing, or did I just screw up?
, , , , jQuery, , , ( - ).