From 4bdba4af85af29f3468dbfc2c626edebe8315911 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Mon, 28 Dec 2015 14:06:50 +0100 Subject: [PATCH] [FIX] web_editor: inline editor should not devore focus The FieldTextHtmlSimple widget would focus on itself when changing its value not by direct user interaction. But if this change was coming from next/previous record, or an onchange that was breaking the "autofocus" heuristic for field in Odoo. With this commit: - the autofocus heuristic is kept, - if focused, selection is set at the end if it is possible on the browser, else (old internet explorer and not visible field) the selection is at the beginning. opw-660486 --- addons/web_editor/static/src/js/backend.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/addons/web_editor/static/src/js/backend.js b/addons/web_editor/static/src/js/backend.js index 17a2df31c6e..3d3b6cb27ee 100644 --- a/addons/web_editor/static/src/js/backend.js +++ b/addons/web_editor/static/src/js/backend.js @@ -103,17 +103,23 @@ var FieldTextHtmlSimple = widget.extend({ return value; }, focus: function() { - var input = !this.get("effective_readonly") && this.$textarea; - return input ? input.focus() : false; + if (this.get("effective_readonly")) { + return false; + } + // on IE an error may occur when creating range on not displayed element + try { + return this.$content.focusInEnd(); + } catch (e) { + return this.$content.focus(); + }; }, render_value: function() { var value = this.get('value'); this.$textarea.val(value || ''); this.$content.html(this.text_to_html(value)); - // on ie an error may occur when creating range on not displayed element - try { - this.$content.focusInEnd(); - } catch (e) {} + if (this.$content.is(document.activeElement)) { + this.focus(); + } var history = this.$content.data('NoteHistory'); if (history && history.recordUndo()) { this.$('.note-toolbar').find('button[data-event="undo"]').attr('disabled', false);