From b4c121db712742894027c4dd4821a4ed6a0f3a3f Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 6 Dec 2013 13:44:31 +0100 Subject: [PATCH] [FIX] bad interaction of editable list with IME MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IME are ways to input language which can't trivially map to a keyboard (e.g. CJK language) with a standard-ish keyboard. For japanese IME this is done by entering text phonetically: text is entered in romaji and automatically converted to hiragana (or katakana) when it matches the transcription a japanese syllable (~phoneme?) e.g. to (と). The text is then split and reprocessed with sequences of hiragana being converted to kanji (or not), and the possibility to pick the right kanji when multiple kanji match e.g. for "Tokyo" toukyou -> とうきょう -> 東京. But to do the edition, keyboard keys are used. For the japanese IMEs (tested on Windows, OSX and Linux) [Space] will do the initial conversion from kana to kanji (and allow selecting an other conversion or a different kana split) and [Return] will validate the current conversion (removing the underline marking "unvalidated" kana or kanji groups). And that's where the problem hit: IME + browser combinations may or may not suppress part of all of the event. Firefox will trigger a keydown of the key which "starts" IME input (e.g. "t") and will trigger a keyup for the validation key (return), except on Linux where the initial keydown is suppressed. Inbetween these, it will fire no keydown, keyup or keypress event but will fire input events (at least on an input element) every time the displayed text changes. Meanwhile webkit browsers will, for each press on the keyboard during IME, * trigger a keydown with the keyCode 229 * trigger a keyup event with the keycode of the key which was actually hit * trigger input events every time the displayed text changes This include meta-operation uses of [Space] and [Return]. MSIE has the same behavior (including triggering the input event), but the keydown event is augmented with ``key`` and ``char`` attributes providing the character matching the key hit to trigger the change. Although the triggering of the input even is useless for the purpose of the editable list (especially here, the purpose of validating a list row with [Return] one fact stands out: keypress is never triggered during IME operations, hitting the [Return] key outside of IME will trigger keydow, keypress, keyup but doing so during IME will only trigger the first and last. Thus by changing the binding from keyup (return) to keypress (return) for a line validation, spurious validation during IME text entry should be avoided. This seems to work correctly on MSIE (Windows), Firefox (Windows, OSX, Linux), Chrome (Windows, OSX, Linux) and Safari (OSX), after testing in IE9, IE10, Chrome 31, Firefox 25 and Safari 7, and a quick test on a task's o2m did not reveal any regression. note: not all differences between various browser/os combinations were inspected in details, there may well be further differences which were not noticed or not relevant to this precise issue. bzr revid: xmo@openerp.com-20131206124431-q4a9l1gn9wjtmlvz --- addons/web/static/src/js/view_form.js | 2 +- addons/web/static/src/js/view_list_editable.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 080cd6f70aa..d91b9c93362 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3980,7 +3980,7 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ } this.cancel_edition(); }, - keyup_ENTER: function () { + keypress_ENTER: function () { // blurring caused by hitting the [Return] key, should skip the // autosave-on-blur and let the handler for [Return] do its thing (save // the current row *anyway*, then create a new one/edit the next one) diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index 512fc4ff373..0cf71660cef 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -451,7 +451,7 @@ openerp.web.list_editable = function (instance) { set_invisible(); }); - this.editor.$el.on('keyup keydown', function (e) { + this.editor.$el.on('keyup keypress keydown', function (e) { if (!self.editor.is_editing()) { return true; } var key = _($.ui.keyCode).chain() .map(function (v, k) { return {name: k, code: v}; }) @@ -485,7 +485,7 @@ openerp.web.list_editable = function (instance) { return self.start_edition(record, options); }); }, - keyup_ENTER: function () { + keypress_ENTER: function () { return this._next(); }, keydown_ESCAPE: function (e) {