1
0
Fork 0
forked from 0x2620/oxjs

fix a bug where space key wouldn't register while autocomplete menu was open

This commit is contained in:
rolux 2011-05-20 09:14:24 +02:00
commit 6e0bafed88
3 changed files with 42 additions and 27 deletions

View file

@ -60,20 +60,26 @@
key = keyNames.join('_');
if (focused !== null) {
Ox.UI.elements[focused].triggerEvent('key_' + key);
// prevent Chrome fromor scrolling
// fixme: backspace -> history.back, blocking it doesn't work
// when the autocomplete menu of an input element has focus
// prevent Chrome from scrolling, or going back in history
if (
[
'down', 'left', 'right', 'space', 'up'
].indexOf(keyBasename) > -1 &&
!Ox.UI.elements[focused].hasClass('OxInput')
'backspace', 'down', 'left', 'right', 'space', 'up'
].indexOf(key) > -1 &&
!Ox.UI.elements[focused].hasClass('OxInput') &&
!Ox.UI.elements[focused].hasClass('OxAutocompleteMenu')
) {
ret = false;
}
// prevent cursor in input field from moving to start or end
if (
['down', 'up'].indexOf(key) > -1 &&
Ox.UI.elements[focused].hasClass('OxAutocompleteMenu')
) {
ret = false;
}
}
if (/^[\w\d](\.numpad)?$|space/.test(key)) {
if (/^[\w\d](\.numpad)?$|^space$/.test(key)) {
// don't register leading spaces or trailing double spaces
if (!(keyName == 'space' && (buffer == '' || / $/.test(buffer)))) {
buffer += keyName == 'space' ? ' ' : keyBasename;