[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
This commit is contained in:
Benoit Socias
2022-07-27 02:18:12 +02:00
parent 0efcb55c6f
commit cc6e888362
@@ -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');