[FIX] web_editor: focus lost with inline editor

When an inline editor is eg. in a form view, the focus is always stolen
by it.

This is because we trigger a mouseup on the editor to update its
toolbars values and informations.

In 10.0 this was not necessary since the default values were sanely set
when the editor was inside the DOM. In 11.0 the editor is not in the DOM
when this is being done and the info was wrong (eg. NaN for text size).

With this commit, we don't steal the focus and get the default like it
was done in 10.0 instead.

fixes #26366
opw-1874880
closes #26582
This commit is contained in:
Nicolas Lempereur
2018-09-03 16:51:20 +02:00
parent af27196fc5
commit 7a453b0b7a
2 changed files with 9 additions and 4 deletions
@@ -207,11 +207,15 @@ define([
var layoutInfo = dom.makeLayoutInfo(target);
/* ODOO: (start_modification */
var $editable = layoutInfo.editable();
if (!event.isDefaultPrevented()) {
modules.editor.saveRange($editable);
if (event.setStyleInfoFromEditable) {
var styleInfo = modules.editor.styleFromNode($editable);
} else {
if (!event.isDefaultPrevented()) {
modules.editor.saveRange($editable);
}
var styleInfo = modules.editor.currentStyle(target);
}
/* ODOO: end_modification) */
var styleInfo = modules.editor.currentStyle(target);
self.updateStyleInfo(styleInfo, layoutInfo);
}, 0);
};
@@ -219,7 +219,8 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend(TranslatableFieldMi
this.$content = this.$('.note-editable:first');
this.$content.html(this._textToHtml(this.value));
// trigger a mouseup to refresh the editor toolbar
this.$content.trigger('mouseup');
var mouseupEvent = $.Event('mouseup', {'setStyleInfoFromEditable': true});
this.$content.trigger(mouseupEvent);
if (this.nodeOptions['style-inline']) {
transcoder.styleToClass(this.$content);
transcoder.imgToFont(this.$content);