From f44ae602352b56ff8a6251c0dddc529b584e37aa Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Tue, 26 Dec 2023 11:22:10 +0100 Subject: [PATCH] [FIX] web_editor, *: do not observe changes related to link edition *: website Commit [1] and [2] modified the link edition code in stable and tweaked the DOM at multiple places... without disabling the main edition mutation observer. Later, [3] tried to fix that but missed some occurrences. Hopefully, this solves the remaining ones. Steps to reproduce: - Enter edit mode - Add a "Text - Image" snippet - Save - Enter edit mode again - Click on the button of the snippet (and do not do anything else) - Click on discard => A popup appears to say you will lose your changes... while you did not make any. [1]: https://github.com/odoo/odoo/commit/99bc9b115dbdfc29260b4ccdb55ffa2ed16dffb3 [2]: https://github.com/odoo/odoo/commit/d00fc75ffdbda1286e4fdb2793cb74fa78f6860d [3]: https://github.com/odoo/odoo/commit/33ef91cc577d8b397a948c430b77c2e038013d2d Related to runbot-18747 Courtesy of @SergeBayet for the test step. X-original-commit: 2a535dfe655bc6a4f4a2d46a6b06a4b8b8029204 Part-of: odoo/odoo#148728 --- .../static/src/js/editor/odoo-editor/src/OdooEditor.js | 4 ++++ .../static/tests/tours/website_no_dirty_page.js | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js index d6da953b59e..353f26c3f3d 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js @@ -2037,12 +2037,16 @@ export class OdooEditor extends EventTarget { // Only add the ZWS at the end if the link is in selection. if (link === linkInSelection) { this._insertLinkZws('end', link); + this.observerUnactive('_setLinkZws_o_link_in_selection'); link.classList.add('o_link_in_selection'); + this.observerActive('_setLinkZws_o_link_in_selection'); didAddZwsInLinkInSelection = true; } const zwsAfter = this._insertLinkZws('after', link); if (!zwsAfter.parentElement || !zwsAfter.parentElement.isContentEditable) { + this.observerUnactive('_setLinkZws_zwsAfter_remove'); zwsAfter.remove(); + this.observerActive('_setLinkZws_zwsAfter_remove'); } } } diff --git a/addons/website/static/tests/tours/website_no_dirty_page.js b/addons/website/static/tests/tours/website_no_dirty_page.js index 58f5ccfc260..d6144573445 100644 --- a/addons/website/static/tests/tours/website_no_dirty_page.js +++ b/addons/website/static/tests/tours/website_no_dirty_page.js @@ -69,5 +69,15 @@ wTourUtils.registerWebsitePreviewTour('website_no_dirty_page', { content: "Make sure the paragraph still acts as a default paragraph", trigger: 'iframe .s_text_image h2 + p.o_default_snippet_text', run: () => null, + }, { + content: "Click on button", + trigger: 'iframe .s_text_image .btn', + run: function (actions) { + actions.click(); + const el = this.$anchor[0]; + const sel = el.ownerDocument.getSelection(); + sel.collapse(el, 0); + el.focus(); + }, }, ]));