Skip to content
Permalink
Browse files

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

Forward-port of #36640 (original: #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
  • Loading branch information...
alexkuhn committed Sep 10, 2019
1 parent 091aa33 commit e27b660765d960ad6fa01a4aa494b33cb5cae7cb
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
@@ -136,8 +136,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() === '') {
@@ -160,7 +165,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({
@@ -237,6 +256,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);
@@ -256,6 +278,8 @@ var SearchView = Widget.extend({
}
}
},
'compositionend .o_searchview_input': '_onCompositionendInput',
'compositionstart .o_searchview_input': '_onCompositionstartInput',
},
defaults: _.extend({}, Widget.prototype.defaults, {
hidden: false,
@@ -681,6 +705,25 @@ var SearchView = Widget.extend({
fv.arch = utils.xml_to_json(doc, true);
return fv;
},

//--------------------------------------------------------------------------
// 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 e27b660

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