[FIX] web: allow user to move cursor in search bar

With the control panel refactoring, the auto_complete widget was set on
a different target, which caused issues with the search bar: the event
handlers for the search bar were triggered before the handlers for the
auto_complete widget.

With this commit, we make sure they are handled in the proper order.

Also, a small piece of code that was supposed to check the position of
the cursor was lost.

closes odoo/odoo#30795
This commit is contained in:
Géry Debongnie
2019-02-04 08:22:34 +00:00
parent dc4e2b92aa
commit 1f5807f1c8
3 changed files with 14 additions and 3 deletions
+2 -2
View File
@@ -179,7 +179,7 @@ QUnit.test('searchview filter messages', function (assert) {
// interact with searchview so that there is only once message
$('.o_searchview_input').val("ab").trigger('keyup');
$('.o_searchview_input_container').trigger($.Event('keydown', { which: $.ui.keyCode.ENTER }));
$('.o_searchview_input').trigger($.Event('keydown', { which: $.ui.keyCode.ENTER }));
assert.strictEqual($('.o_searchview_facet').length, 1,
"the searchview should have a facet");
@@ -191,7 +191,7 @@ QUnit.test('searchview filter messages', function (assert) {
// interact with search view so that there are no matching messages
testUtils.dom.click($('.o_facet_remove'));
$('.o_searchview_input').val("abcd").trigger('keyup');
$('.o_searchview_input_container').trigger($.Event('keydown', { which: $.ui.keyCode.ENTER }));
$('.o_searchview_input').trigger($.Event('keydown', { which: $.ui.keyCode.ENTER }));
assert.strictEqual($('.o_searchview_facet').length, 1,
"the searchview should have a facet");
@@ -142,6 +142,7 @@ var SearchBar = Widget.extend({
var self = this;
this._setupAutoCompletionWidgets();
this.autoComplete = new AutoComplete(this, {
$input: this.$('input'),
source: this._getAutoCompleteSources.bind(this),
select: this._onAutoCompleteSelected.bind(this),
get_search_string: function () {
@@ -19,7 +19,7 @@ return Widget.extend({
// to obtain the current search string.
init: function (parent, options) {
this._super(parent);
this.$input = parent.$el;
this.$input = options.$input;
this.source = options.source;
this.select = options.select;
this.get_search_string = options.get_search_string;
@@ -90,14 +90,24 @@ return Widget.extend({
ev.preventDefault();
break;
case $.ui.keyCode.RIGHT:
if(self.$input[0].selectionStart < self.search_string.length) {
ev.stopPropagation();
return;
}
self.searching = false;
var current = self.current_result;
if (current && current.expand && !current.expanded) {
self.expand();
self.searching = true;
ev.stopPropagation();
}
ev.preventDefault();
break;
case $.ui.keyCode.LEFT:
if(self.$input[0].selectionStart > 0) {
ev.stopPropagation();
}
break;
case $.ui.keyCode.ESCAPE:
self.close();
self.searching = false;