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
parent 0ebd4efc72
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;

View file

@ -305,16 +305,37 @@ Ox.Input = function(options, self) {
var length = self.options.value.length,
deleted = length <= oldValue.length - (oldCursor[1] - oldCursor[0]),
newValue = values[0] ?
((self.options.autocompleteReplaceCorrect || !deleted) ?
values[0] : self.options.value) :
(self.options.autocompleteReplaceCorrect ? oldValue : self.options.value),
newLength = newValue.length,
newValue, newLength,
pos = cursor(),
selected = -1,
selectEnd = length == 0 || (values[0] && values[0].length),
value;
if (values[0]) {
if (self.options.autocompleteReplaceCorrect || !deleted) {
newValue = values[0];
} else {
newValue = self.options.value;
}
} else {
if (self.options.autocompleteReplaceCorrect) {
newValue = oldValue;
} else {
newValue = self.options.value
}
}
newLength = newValue.length;
/*
if (self.options.autocompleteReplaceCorrect) {
if (values[0]) {
newValue = deleted ? oldValue : values[0];
} else {
newValue = self.options.value;
}
}
*/
//Ox.print('selectEnd', selectEnd)
if (self.options.autocompleteReplace) {
@ -380,22 +401,9 @@ Ox.Input = function(options, self) {
}
//size: self.options.size
})
.addClass('OxAutocompleteMenu')
.bindEvent({
click: clickMenu,
key_left: function() {
cursor(cursor()[0] - 1);
},
key_right: function() {
cursor(cursor()[0] + 1);
},
key_shift_left: function() {
var cursor = cursor();
cursor(cursor[0] - 1, cursor[1]);
},
key_shift_right: function() {
var cursor = cursor();
cursor(cursor[0], cursor[1] + 1);
}
click: clickMenu
});
if (self.options.autocompleteReplace) {
menu.bindEvent({

View file

@ -460,6 +460,7 @@ Ox.VideoEditor = function(options, self) {
self.$findInput = Ox.Input({
autocomplete: self.words,
autocompleteReplace: true,
autocompleteSelect: true,
autocompleteSelectHighlight: true,
autocompleteSelectMax: 10,