0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-01-03 05:00:13 -05:00

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.
This commit is contained in:
Neil Jenkins 2012-03-30 10:18:17 +11:00
parent f0ba6216cc
commit 89eb88ce15

View file

@ -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,
// 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 ) );