fix a bug where space key wouldn't register while autocomplete menu was open
This commit is contained in:
parent
0ebd4efc72
commit
6e0bafed88
3 changed files with 42 additions and 27 deletions
|
@ -60,20 +60,26 @@
|
||||||
key = keyNames.join('_');
|
key = keyNames.join('_');
|
||||||
if (focused !== null) {
|
if (focused !== null) {
|
||||||
Ox.UI.elements[focused].triggerEvent('key_' + key);
|
Ox.UI.elements[focused].triggerEvent('key_' + key);
|
||||||
// prevent Chrome fromor scrolling
|
// prevent Chrome from scrolling, or going back in history
|
||||||
// fixme: backspace -> history.back, blocking it doesn't work
|
|
||||||
// when the autocomplete menu of an input element has focus
|
|
||||||
if (
|
if (
|
||||||
[
|
[
|
||||||
'down', 'left', 'right', 'space', 'up'
|
'backspace', 'down', 'left', 'right', 'space', 'up'
|
||||||
].indexOf(keyBasename) > -1 &&
|
].indexOf(key) > -1 &&
|
||||||
!Ox.UI.elements[focused].hasClass('OxInput')
|
!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;
|
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
|
// don't register leading spaces or trailing double spaces
|
||||||
if (!(keyName == 'space' && (buffer == '' || / $/.test(buffer)))) {
|
if (!(keyName == 'space' && (buffer == '' || / $/.test(buffer)))) {
|
||||||
buffer += keyName == 'space' ? ' ' : keyBasename;
|
buffer += keyName == 'space' ? ' ' : keyBasename;
|
||||||
|
|
|
@ -305,16 +305,37 @@ Ox.Input = function(options, self) {
|
||||||
|
|
||||||
var length = self.options.value.length,
|
var length = self.options.value.length,
|
||||||
deleted = length <= oldValue.length - (oldCursor[1] - oldCursor[0]),
|
deleted = length <= oldValue.length - (oldCursor[1] - oldCursor[0]),
|
||||||
newValue = values[0] ?
|
newValue, newLength,
|
||||||
((self.options.autocompleteReplaceCorrect || !deleted) ?
|
|
||||||
values[0] : self.options.value) :
|
|
||||||
(self.options.autocompleteReplaceCorrect ? oldValue : self.options.value),
|
|
||||||
newLength = newValue.length,
|
|
||||||
pos = cursor(),
|
pos = cursor(),
|
||||||
selected = -1,
|
selected = -1,
|
||||||
selectEnd = length == 0 || (values[0] && values[0].length),
|
selectEnd = length == 0 || (values[0] && values[0].length),
|
||||||
value;
|
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)
|
//Ox.print('selectEnd', selectEnd)
|
||||||
|
|
||||||
if (self.options.autocompleteReplace) {
|
if (self.options.autocompleteReplace) {
|
||||||
|
@ -380,22 +401,9 @@ Ox.Input = function(options, self) {
|
||||||
}
|
}
|
||||||
//size: self.options.size
|
//size: self.options.size
|
||||||
})
|
})
|
||||||
|
.addClass('OxAutocompleteMenu')
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
click: clickMenu,
|
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);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
if (self.options.autocompleteReplace) {
|
if (self.options.autocompleteReplace) {
|
||||||
menu.bindEvent({
|
menu.bindEvent({
|
||||||
|
|
|
@ -460,6 +460,7 @@ Ox.VideoEditor = function(options, self) {
|
||||||
|
|
||||||
self.$findInput = Ox.Input({
|
self.$findInput = Ox.Input({
|
||||||
autocomplete: self.words,
|
autocomplete: self.words,
|
||||||
|
autocompleteReplace: true,
|
||||||
autocompleteSelect: true,
|
autocompleteSelect: true,
|
||||||
autocompleteSelectHighlight: true,
|
autocompleteSelectHighlight: true,
|
||||||
autocompleteSelectMax: 10,
|
autocompleteSelectMax: 10,
|
||||||
|
|
Loading…
Reference in a new issue