Skip to content
Permalink
Browse files

[FIX] web: use search view input with composition mode

Forward-port of #35789

Before this commit, search view was barely usable with Japanese IME.

For instance, when pressing ENTER while in composition mode and
IME prompts some suggestions, it made a search with the updated input
content. The expected behaviour should have been to update the input
content, without making the search yet.

This commit fixes the issue by turning off some actions of the
search view when typing during composition mode.

opw-2061590

closes #36640

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
  • Loading branch information...
alexkuhn committed Sep 10, 2019
1 parent 3004d37 commit d0e458b093239aa12c1b1f46ca7a5eb1b52e6f24
Showing with 56 additions and 3 deletions.
  1. +44 −1 addons/web/static/src/js/chrome/search_view.js
  2. +12 −2 addons/web/static/src/js/widgets/auto_complete.js
@@ -135,8 +135,13 @@ var InputView = Widget.extend({
focus: function () { this.trigger('focused', this); },
blur: function () { this.$el.val(''); this.trigger('blurred', this); },
keydown: 'onKeydown',
'compositionend': '_onCompositionend',
'compositionstart': '_onCompositionstart',
},
onKeydown: function (e) {
if (this._isComposing) {
return;
}
switch (e.which) {
case $.ui.keyCode.BACKSPACE:
if(this.$el.val() === '') {
@@ -159,7 +164,21 @@ var InputView = Widget.extend({
}
break;
}
}
},
/**
* @private
* @param {CompositionEvent} ev
*/
_onCompositionend: function (ev) {
this._isComposing = false;
},
/**
* @private
* @param {CompositionEvent} ev
*/
_onCompositionstart: function (ev) {
this._isComposing = true;
},
});

var FacetView = Widget.extend({
@@ -236,6 +255,9 @@ var SearchView = Widget.extend({
this.toggle_buttons();
},
'keydown .o_searchview_input, .o_searchview_facet': function (e) {
if (this._isInputComposing) {
return;
}
switch(e.which) {
case $.ui.keyCode.LEFT:
this.focusPreceding(e.target);
@@ -249,6 +271,8 @@ var SearchView = Widget.extend({
break;
}
},
'compositionend .o_searchview_input': '_onCompositionendInput',
'compositionstart .o_searchview_input': '_onCompositionstartInput',
},
defaults: _.extend({}, Widget.prototype.defaults, {
hidden: false,
@@ -603,6 +627,25 @@ var SearchView = Widget.extend({
current_category = filter.category;
});
},

//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------

/**
* @rivate
* @param {CompositionEvent} ev
*/
_onCompositionendInput: function () {
this._isInputComposing = false;
},
/**
* @rivate
* @param {CompositionEvent} ev
*/
_onCompositionstartInput: function () {
this._isInputComposing = true;
},
});

_.extend(SearchView, {
@@ -29,16 +29,23 @@ return Widget.extend({
this.searching = true;
this.search_string = '';
this.current_search = null;
this._isInputComposing = false;
},
start: function () {
var self = this;
this.$input.on('compositionend', function (ev) {
self._isInputComposing = false;
});
this.$input.on('compositionstart', function (ev) {
self._isInputComposing = true;
});
this.$input.on('keyup', function (ev) {
if (ev.which === $.ui.keyCode.RIGHT) {
if (ev.which === $.ui.keyCode.RIGHT && !self._isInputComposing) {
self.searching = true;
ev.preventDefault();
return;
}
if (ev.which === $.ui.keyCode.ENTER) {
if (ev.which === $.ui.keyCode.ENTER && !self._isInputComposing) {
if (self.search_string.length) {
self.select_item(ev);
}
@@ -65,6 +72,9 @@ return Widget.extend({
}
});
this.$input.on('keydown', function (ev) {
if (self._isInputComposing) {
return;
}
switch (ev.which) {
case $.ui.keyCode.ENTER:

0 comments on commit d0e458b

Please sign in to comment.
You can’t perform that action at this time.