@@ -257,8 +257,8 @@ define(function (require, exports, module) {
257257 $ ( this ) . on ( "cursorActivity" , function ( jqEvent , editor ) {
258258 self . _handleCursorActivity ( jqEvent ) ;
259259 } ) ;
260- $ ( this ) . on ( "keyEvent " , function ( jqEvent , editor , cmEvent ) {
261- self . _handleKeyEvents ( cmEvent ) ;
260+ $ ( this ) . on ( "keypress " , function ( jqEvent , editor , cmEvent ) {
261+ self . _handleKeypressEvents ( cmEvent ) ;
262262 } ) ;
263263 $ ( this ) . on ( "change" , function ( jqEvent , editor , changeList ) {
264264 self . _handleEditorChange ( changeList ) ;
@@ -332,24 +332,23 @@ define(function (require, exports, module) {
332332 * back-indenting it if so.
333333 */
334334 Editor . prototype . _checkElectricChars = function ( event ) {
335- var instance = this . _codeMirror ;
336- if ( event . type === "keypress" ) {
337- var keyStr = String . fromCharCode ( event . which || event . keyCode ) ;
338- if ( / [ \] \{ \} \) ] / . test ( keyStr ) ) {
339- // If all text before the cursor is whitespace, auto-indent it
340- var cursor = this . getCursorPos ( ) ;
341- var lineStr = instance . getLine ( cursor . line ) ;
342- var nonWS = lineStr . search ( / \S / ) ;
343-
344- if ( nonWS === - 1 || nonWS >= cursor . ch ) {
345- // Need to do the auto-indent on a timeout to ensure
346- // the keypress is handled before auto-indenting.
347- // This is the same timeout value used by the
348- // electricChars feature in CodeMirror.
349- window . setTimeout ( function ( ) {
350- instance . indentLine ( cursor . line ) ;
351- } , 75 ) ;
352- }
335+ var instance = this . _codeMirror ,
336+ keyStr = String . fromCharCode ( event . which || event . keyCode ) ;
337+
338+ if ( / [ \] \{ \} \) ] / . test ( keyStr ) ) {
339+ // If all text before the cursor is whitespace, auto-indent it
340+ var cursor = this . getCursorPos ( ) ;
341+ var lineStr = instance . getLine ( cursor . line ) ;
342+ var nonWS = lineStr . search ( / \S / ) ;
343+
344+ if ( nonWS === - 1 || nonWS >= cursor . ch ) {
345+ // Need to do the auto-indent on a timeout to ensure
346+ // the keypress is handled before auto-indenting.
347+ // This is the same timeout value used by the
348+ // electricChars feature in CodeMirror.
349+ window . setTimeout ( function ( ) {
350+ instance . indentLine ( cursor . line ) ;
351+ } , 75 ) ;
353352 }
354353 }
355354 } ;
@@ -379,7 +378,7 @@ define(function (require, exports, module) {
379378 * Handle CodeMirror key events.
380379 * @param {!Event } event
381380 */
382- Editor . prototype . _handleKeyEvents = function ( event ) {
381+ Editor . prototype . _handleKeypressEvents = function ( event ) {
383382 this . _checkElectricChars ( event ) ;
384383 } ;
385384
@@ -693,7 +692,8 @@ define(function (require, exports, module) {
693692
694693 // Redispatch these CodeMirror key events as jQuery events
695694 function _onKeyEvent ( instance , event ) {
696- $ ( self ) . triggerHandler ( "keyEvent" , [ self , event ] ) ;
695+ $ ( self ) . triggerHandler ( "keyEvent" , [ self , event ] ) ; // deprecated
696+ $ ( self ) . triggerHandler ( event . type , [ self , event ] ) ;
697697 return event . defaultPrevented ; // false tells CodeMirror we didn't eat the event
698698 }
699699 this . _codeMirror . on ( "keydown" , _onKeyEvent ) ;
0 commit comments