diff --git a/source/Ox.UI/js/Core/Ox.Keyboard.js b/source/Ox.UI/js/Core/Ox.Keyboard.js index b0bc70bc..804ded99 100644 --- a/source/Ox.UI/js/Core/Ox.Keyboard.js +++ b/source/Ox.UI/js/Core/Ox.Keyboard.js @@ -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; diff --git a/source/Ox.UI/js/Form/Ox.Input.js b/source/Ox.UI/js/Form/Ox.Input.js index 3868b2d2..db66e4bd 100644 --- a/source/Ox.UI/js/Form/Ox.Input.js +++ b/source/Ox.UI/js/Form/Ox.Input.js @@ -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({ diff --git a/source/Ox.UI/js/Video/Ox.VideoEditor.js b/source/Ox.UI/js/Video/Ox.VideoEditor.js index 79f23681..f77d3f01 100644 --- a/source/Ox.UI/js/Video/Ox.VideoEditor.js +++ b/source/Ox.UI/js/Video/Ox.VideoEditor.js @@ -460,6 +460,7 @@ Ox.VideoEditor = function(options, self) { self.$findInput = Ox.Input({ autocomplete: self.words, + autocompleteReplace: true, autocompleteSelect: true, autocompleteSelectHighlight: true, autocompleteSelectMax: 10,