[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) <dmo@odoo.com>
This commit is contained in:
Nicolas Bayet
2022-10-24 16:12:52 +02:00
parent 4e796124c5
commit 0cab7bccb5
@@ -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) {