From 89eb88ce158fb143471491ccd1ed0852ac1113e4 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Fri, 30 Mar 2012 10:18:17 +1100 Subject: [PATCH] Fix repeating keys don't fire handlers. Holding down a key will trigger it repeatedly; we need to capture all of these events to override backspace/enter etc. --- source/Editor.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/source/Editor.js b/source/Editor.js index ec270b2..fa4df7e 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -1434,12 +1434,20 @@ 'ctrl-shift-z': mapKeyTo( redo ) }; - addEventListener( 'keydown', function ( event ) { - // Ref: http://unixpapa.com/js/key.html - var code = event.keyCode || event.which, + // Ref: http://unixpapa.com/js/key.html + // Opera does not fire keydown repeatedly. + addEventListener( isOpera ? 'keypress' : 'keydown', + function ( event ) { + var code = event.keyCode, key = keys[ code ] || String.fromCharCode( code ).toLowerCase(), modifiers = ''; + // On keypress, delete and '.' both have event.keyCode 46 + // Must check event.which to differentiate. + if ( isOpera && event.which === 46 ) { + key = '.'; + } + // Function keys if ( 111 < code && code < 124 ) { key = 'f' + ( code - 111 ); @@ -1724,7 +1732,7 @@ if ( win.onEditorLoad ) { win.onEditorLoad( win.editor ); - delete win.onEditorLoad; + win.onEditorLoad = null; } }( document ) ); \ No newline at end of file