autocomplete menu improvements (left/right keys while menu is visible, properly set selected in all cases)
This commit is contained in:
parent
3087690d89
commit
0ebd4efc72
1 changed files with 31 additions and 5 deletions
|
@ -352,7 +352,9 @@ Ox.Input = function(options, self) {
|
|||
};
|
||||
}
|
||||
return ret;
|
||||
}),
|
||||
})
|
||||
});
|
||||
self.$autocompleteMenu.options({
|
||||
selected: selected
|
||||
}).showMenu();
|
||||
} else {
|
||||
|
@ -378,7 +380,23 @@ Ox.Input = function(options, self) {
|
|||
}
|
||||
//size: self.options.size
|
||||
})
|
||||
.bindEvent('click', clickMenu);
|
||||
.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);
|
||||
}
|
||||
});
|
||||
if (self.options.autocompleteReplace) {
|
||||
menu.bindEvent({
|
||||
deselect: deselectMenu,
|
||||
|
@ -632,7 +650,11 @@ Ox.Input = function(options, self) {
|
|||
hasDeletedSelectedEnd = (event.keyCode == 8 || event.keyCode == 46) &&
|
||||
oldCursor[0] < oldCursor[1] && oldCursor[1] == oldValue.length;
|
||||
//Ox.print('keypress', event.keyCode)
|
||||
if (event.keyCode != 9 && (self.options.type == 'textarea' || event.keyCode != 13) && event.keyCode != 27) { // fixme: can't 13 and 27 return false?
|
||||
if (
|
||||
event.keyCode != 9 &&
|
||||
(self.options.type == 'textarea' || event.keyCode != 13) &&
|
||||
event.keyCode != 27
|
||||
) { // fixme: can't 13 and 27 return false?
|
||||
setTimeout(function() { // wait for val to be set
|
||||
var value = self.$input.val();
|
||||
if (self.options.autocompleteReplaceCorrect && hasDeletedSelectedEnd) {
|
||||
|
@ -652,8 +674,12 @@ Ox.Input = function(options, self) {
|
|||
}
|
||||
}, 0);
|
||||
}
|
||||
if ((event.keyCode == 38 || event.keyCode == 40) && self.options.autocompleteSelect && self.$autocompleteMenu.is(':visible')) {
|
||||
return false;
|
||||
if (
|
||||
(event.keyCode == 38 || event.keyCode == 40) &&
|
||||
self.options.autocompleteSelect &&
|
||||
self.$autocompleteMenu.is(':visible')
|
||||
) {
|
||||
//return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue