From 74dc80e796549a8e39d94e33db7108eb7e9502a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Geelen=20=28sge=29?= Date: Thu, 27 Apr 2023 13:01:13 +0000 Subject: [PATCH] [FIX] web_editor: better urgent save for to inline html field Reorganize the urgent save steps to call `_toInline` before the urgent `updateValue`. This will give a chance to the _toInline to finish before the `updateValue` if no asynchronous process is triggered during the inlining process. In case we have some async stuff that delay the `_toInline` completion, we keep the second `updateValue` which will wait for the asynchronous completion, as before. task-3222474 X-original-commit: 85540a58a58b5f60b587697490fe837b3e4a69ec Part-of: odoo/odoo#124020 --- .../web_editor/static/src/js/backend/html_field.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/addons/web_editor/static/src/js/backend/html_field.js b/addons/web_editor/static/src/js/backend/html_field.js index 93834caad1b..477d5bd6786 100644 --- a/addons/web_editor/static/src/js/backend/html_field.js +++ b/addons/web_editor/static/src/js/backend/html_field.js @@ -397,15 +397,21 @@ export class HtmlField extends Component { } async commitChanges({ urgent } = {}) { if (this._isDirty() || urgent) { + let toInlinePromise; + if (this.wysiwyg) { + this.wysiwyg.odooEditor.observerUnactive('commitChanges'); + await this.wysiwyg.savePendingImages(); + if (this.props.isInlineStyle) { + // Avoid listening to changes made during the _toInline process. + toInlinePromise = this._toInline(); + } + } if (urgent) { await this.updateValue(); } if (this.wysiwyg) { - // Avoid listening to changes made during the _toInline process. - this.wysiwyg.odooEditor.observerUnactive('commitChanges'); - await this.wysiwyg.savePendingImages(); if (this.props.isInlineStyle) { - await this._toInline(); + await toInlinePromise; } this.wysiwyg.odooEditor.observerActive('commitChanges'); }