From 0cab7bccb5d2be82e3f2dd1a6574e0bb5ad856a1 Mon Sep 17 00:00:00 2001 From: Nicolas Bayet Date: Mon, 24 Oct 2022 09:10:54 +0000 Subject: [PATCH] [FIX] web_editor: prevent reset editor When a change was made on the same record, the editor could wrongly be reset. Step to reproduce: - Go in knowledge app - Click inside the editor outside a template block - Click on inside a template block - Click inside the editor outsie a template block => The editor is reset closes odoo/odoo#103947 X-original-commit: d0a079a76c3f5078178717966e3d4caf0987ebf9 Signed-off-by: David Monjoie (dmo) --- .../static/src/js/backend/html_field.js | 22 +++++++++++++++---- 1 file changed, 18 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 25964dc0665..e5740bd2550 100644 --- a/addons/web_editor/static/src/js/backend/html_field.js +++ b/addons/web_editor/static/src/js/backend/html_field.js @@ -51,11 +51,17 @@ export class HtmlFieldWysiwygAdapterComponent extends ComponentAdapter { updateWidget(newProps) { const lastValue = String(this.props.widgetArgs[0].value || ''); + const lastRecordInfo = this.props.widgetArgs[0].recordInfo; const lastCollaborationChannel = this.props.widgetArgs[0].collaborationChannel; const newValue = String(newProps.widgetArgs[0].value || ''); + const newRecordInfo = newProps.widgetArgs[0].recordInfo; const newCollaborationChannel = newProps.widgetArgs[0].collaborationChannel; - if ((newValue !== newProps.editingValue && lastValue !== newValue) || !_.isEqual(lastCollaborationChannel, newCollaborationChannel)) { + if ( + (newValue !== newProps.editingValue && lastValue !== newValue) || + !_.isEqual(lastRecordInfo, newRecordInfo) || + !_.isEqual(lastCollaborationChannel, newCollaborationChannel)) + { this.widget.resetEditor(newValue, { collaborationChannel: newCollaborationChannel, }); @@ -99,13 +105,23 @@ export class HtmlField extends Component { this.cssEditAsset = await ajax.loadAsset(this.props.cssEditAssetId || 'web_editor.assets_edit_html_field'); } }); + this._lastRecordInfo = { + res_model: this.props.record.resModel, + res_id: this.props.record.resId, + }; onWillUpdateProps((newProps) => { if (!newProps.readonly && this.state.iframeVisible) { this.state.iframeVisible = false; } - if (!this._selfUpdating) { + + const newRecordInfo = { + res_model: this.props.record.resModel, + res_id: this.props.record.resId, + }; + if (!_.isEqual(this._lastRecordInfo, newRecordInfo)) { this.currentEditingValue = undefined; } + this._lastRecordInfo = newRecordInfo; }); useEffect(() => { (async () => { @@ -266,9 +282,7 @@ export class HtmlField extends Component { this.props.setDirty(true); } this.currentEditingValue = value; - this._selfUpdating = true; await this.props.update(value); - this._selfUpdating = false; } } async startWysiwyg(wysiwyg) {