diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 6bd58d843d1..35dbebac724 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -1164,7 +1164,8 @@ export class Wysiwyg extends Component { // o_modified_image_to_save by _saveB64Image to request the saving // of the pre-converted webp resizes and all the equivalent jpgs. const b64Proms = [...editableEl.querySelectorAll('.o_b64_image_to_save')].map(async el => { - if (el.closest(".o_dirty") !== editableEl) { + const dirtyEditable = el.closest(".o_dirty"); + if (dirtyEditable && dirtyEditable !== editableEl) { // Do nothing as there is an editable element closer to the // image that will perform the `_saveB64Image()` call with // the correct "resModel" and "resId" parameters. @@ -1173,7 +1174,8 @@ export class Wysiwyg extends Component { await this._saveB64Image(el, resModel, resId); }); const modifiedProms = [...editableEl.querySelectorAll('.o_modified_image_to_save')].map(async el => { - if (el.closest(".o_dirty") !== editableEl) { + const dirtyEditable = el.closest(".o_dirty"); + if (dirtyEditable && dirtyEditable !== editableEl) { // Do nothing as there is an editable element closer to the // image that will perform the `_saveModifiedImage()` call // with the correct "resModel" and "resId" parameters. diff --git a/addons/web_editor/static/tests/html_field_tests.js b/addons/web_editor/static/tests/html_field_tests.js index 2bbe01f69cd..8097edc83b3 100644 --- a/addons/web_editor/static/tests/html_field_tests.js +++ b/addons/web_editor/static/tests/html_field_tests.js @@ -8,6 +8,7 @@ import { parseHTML } from "@web_editor/js/editor/odoo-editor/src/utils/utils"; import { onRendered } from "@odoo/owl"; import { wysiwygData } from "@web_editor/../tests/test_utils"; import { OdooEditor } from '@web_editor/js/editor/odoo-editor/src/OdooEditor'; +import { Wysiwyg } from "@web_editor/js/wysiwyg/wysiwyg"; // Legacy import legacyEnv from '@web/legacy/js/common_env'; @@ -415,7 +416,6 @@ QUnit.module("WebEditor.HtmlField", ({ beforeEach }) => { // Replace the empty paragraph with a paragrah containing an unsaved // modified image - editor.editable.classList.add("o_dirty"); const imageContainerElement = parseHTML(imageContainerHTML).firstChild; let paragraph = editor.editable.querySelector(".test_target"); editor.editable.replaceChild(imageContainerElement, paragraph); @@ -436,6 +436,119 @@ QUnit.module("WebEditor.HtmlField", ({ beforeEach }) => { await nextTick(); }); + QUnit.test("Pasted/dropped images are converted to attachments on save", async (assert) => { + assert.expect(4); + + // Patch to get a promise to get the htmlField component instance when + // the wysiwyg is instancied. + const htmlFieldPromise = makeDeferred(); + patchWithCleanup(HtmlField.prototype, { + async startWysiwyg() { + await super.startWysiwyg(...arguments); + await nextTick(); + htmlFieldPromise.resolve(this); + } + }); + // Add a partner record + serverData.models.partner.records.push({ + id: 1, + txt: "