better behaviour when pressing backspace while autocomplete is set to replace, but not to correct

This commit is contained in:
rolux 2011-05-20 09:42:17 +02:00
parent 6e0bafed88
commit 7b15d2bb8f

View file

@ -304,7 +304,6 @@ Ox.Input = function(options, self) {
//Ox.print('autocompleteCallback', values[0], self.options.value, self.options.value.length, oldValue, oldCursor) //Ox.print('autocompleteCallback', values[0], self.options.value, self.options.value.length, oldValue, oldCursor)
var length = self.options.value.length, var length = self.options.value.length,
deleted = length <= oldValue.length - (oldCursor[1] - oldCursor[0]),
newValue, newLength, newValue, newLength,
pos = cursor(), pos = cursor(),
selected = -1, selected = -1,
@ -312,7 +311,7 @@ Ox.Input = function(options, self) {
value; value;
if (values[0]) { if (values[0]) {
if (self.options.autocompleteReplaceCorrect || !deleted) { if (self.options.autocompleteReplace) {
newValue = values[0]; newValue = values[0];
} else { } else {
newValue = self.options.value; newValue = self.options.value;
@ -326,16 +325,6 @@ Ox.Input = function(options, self) {
} }
newLength = newValue.length; 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) {
@ -657,7 +646,6 @@ Ox.Input = function(options, self) {
newValue = oldValue.substr(0, oldCursor[0] - 1), newValue = oldValue.substr(0, oldCursor[0] - 1),
hasDeletedSelectedEnd = (event.keyCode == 8 || event.keyCode == 46) && hasDeletedSelectedEnd = (event.keyCode == 8 || event.keyCode == 46) &&
oldCursor[0] < oldCursor[1] && oldCursor[1] == oldValue.length; oldCursor[0] < oldCursor[1] && oldCursor[1] == oldValue.length;
//Ox.print('keypress', event.keyCode)
if ( if (
event.keyCode != 9 && event.keyCode != 9 &&
(self.options.type == 'textarea' || event.keyCode != 13) && (self.options.type == 'textarea' || event.keyCode != 13) &&
@ -665,9 +653,8 @@ Ox.Input = function(options, self) {
) { // fixme: can't 13 and 27 return false? ) { // fixme: can't 13 and 27 return false?
setTimeout(function() { // wait for val to be set setTimeout(function() { // wait for val to be set
var value = self.$input.val(); var value = self.$input.val();
if (self.options.autocompleteReplaceCorrect && hasDeletedSelectedEnd) { if (self.options.autocompleteReplace && hasDeletedSelectedEnd) {
//Ox.print(value, '->', newValue); value = newValue;
value = newValue; // value.substr(0, value.length - 1);
self.$input.val(value); self.$input.val(value);
} }
if (value != self.options.value) { if (value != self.options.value) {