From 0e22763a85ee2f4caf663185eb70d3d181b954b0 Mon Sep 17 00:00:00 2001 From: Nicolas Bayet Date: Wed, 10 Jan 2024 10:29:12 +0100 Subject: [PATCH] [FIX] web_editor: use setValue instead of resetEdior when restore Before this commit, when restoring a document was made, it would reset the content of the editor without any consideration for the mechanism that detect stale documents and without any consideration for the collaboration. This commit fixes 2 problems in one shot: 1) Any change made in the editor after a restore was impossible to save. The reason is that the restored version would reset the wysiwyg without the id `data-last-history-steps` of the version in database in the historyIds of the odooEditor wich subsequently would trigger the stale document detection, preventing the save. 2) The reset would be propagated to other peers in collaboration. The reason is the same as the 1st problem, the wysiwyg would be reseted, not informing other peers of that reset. task-3675074 Part-of: odoo/odoo#148826 --- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 1c01c6b1356..4edb4677ada 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -247,16 +247,23 @@ export class Wysiwyg extends Component { const newRecordInfo = newProps.options.recordInfo; const newCollaborationChannel = newProps.options.collaborationChannel; + const isDifferentRecord = + JSON.stringify(lastRecordInfo) !== JSON.stringify(newRecordInfo) || + JSON.stringify(lastCollaborationChannel) !== JSON.stringify(newCollaborationChannel); + if ( ( stripHistoryIds(newValue) !== stripHistoryIds(newProps.editingValue) && stripHistoryIds(lastValue) !== stripHistoryIds(newValue) ) || - JSON.stringify(lastRecordInfo) !== JSON.stringify(newRecordInfo) || - JSON.stringify(lastCollaborationChannel) !== JSON.stringify(newCollaborationChannel) + isDifferentRecord ) { - this.resetEditor(newValue, newProps.options); + if (isDifferentRecord) { + this.resetEditor(newValue, newProps.options); + } else { + this.setValue(newValue); + } this.env.onWysiwygReset && this.env.onWysiwygReset(); } });