From cc6e88836205d492f5d07ba736473f19476fbdad Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Tue, 12 Jul 2022 13:15:45 +0000 Subject: [PATCH] [FIX] web_editor: keep classes that exist in both source & target media Since [1] when replacing a media by a media of the same type or that has some extra classes in common, those classes were removed instead of being kept. This commit makes sure only the classes that do not exist in the newly selected media type are removed. Steps to reproduce: - Drop a "Text - Image". - Replace the image by an icon. - Apply a circle effect and colors on the icon. - Replace the icon by another icon. => The applied effect and colors were lost. [1]: https://github.com/odoo/odoo/commit/9ca349bbdb75505e8dbd31898f05ba8d694e7953 task-2687506 Part-of: odoo/odoo#95853 --- .../components/media_dialog/media_dialog.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/components/media_dialog/media_dialog.js b/addons/web_editor/static/src/components/media_dialog/media_dialog.js index ec9a4c4ff12..d23d0bb0891 100644 --- a/addons/web_editor/static/src/components/media_dialog/media_dialog.js +++ b/addons/web_editor/static/src/components/media_dialog/media_dialog.js @@ -172,7 +172,23 @@ export class MediaDialog extends Component { } } } - element.classList.remove(...extraClassesToRemove); + // Remove classes that do not also exist in the target type. + element.classList.remove(...extraClassesToRemove.filter(candidateName => { + for (const name of TABS[this.state.activeTab].Component.mediaExtraClasses) { + if (typeof(name) === 'string') { + if (candidateName === name) { + return false; + } + } else { // Regex + for (const className of element.classList) { + if (className.match(candidateName)) { + return false; + } + } + } + } + return true; + })); } element.classList.remove(...this.initialIconClasses); element.classList.remove('o_modified_image_to_save');