[FIX] web_editor: fix replacing media leaving unexpected elements
Previously, changing a media from a video/icon/document to a different type would leave empty elements in the DOM, this is because summernote's range API `range.insertNode` function deletes the content but not the structure (HTML elements). This commit fixes that by using jQuery's replaceWith method instead of summernote's insertNode when a media was found, and only using summernote in case no media was found (eg. a text range). Part of https://github.com/odoo/odoo/pull/64234 X-original-commit: 63f80995a05eeab1061b769c7733a1cfa98c726e
This commit is contained in:
@@ -448,10 +448,15 @@ eventHandler.modules.imageDialog.showImageDialog = function ($editable) {
|
||||
onUpload: $editable.data('callbacks').onUpload,
|
||||
noVideos: options && options.noVideos,
|
||||
},
|
||||
onSave: function (media) {
|
||||
if(media && !document.body.contains(media)) {
|
||||
r.insertNode(media);
|
||||
};
|
||||
onSave: function (newMedia) {
|
||||
if (!newMedia) {
|
||||
return;
|
||||
}
|
||||
if (media) {
|
||||
$(media).replaceWith(newMedia);
|
||||
} else {
|
||||
r.insertNode(newMedia);
|
||||
}
|
||||
},
|
||||
});
|
||||
return new $.Deferred().reject();
|
||||
|
||||
Reference in New Issue
Block a user