[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
This commit is contained in:
qsm-odoo
2024-01-10 10:28:17 +00:00
parent 0a948a8386
commit f44ae60235
2 changed files with 14 additions and 0 deletions
@@ -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');
}
}
}
@@ -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();
},
},
]));