From 9ed20a5260d3b4237f2a5ca36e1ce376aaa1ff99 Mon Sep 17 00:00:00 2001 From: Jinjiu Liu Date: Wed, 4 Oct 2023 15:05:52 +0200 Subject: [PATCH] [FIX] web_editor: avoid contenteditable reset when doing link isolation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reproduction: 1. install website, drag a block with button 2. click at the beginning of the button text 3. type something, it will be outside of the button area Reason: The contenteditable is reset depending on the o_editable and o_not_editable class in the _onPostSanitize function. Fix: don’t do the resetting when we have the _fixLinkMutatedElements key in OdooEditor as it indicates that the link isolation trick is executing task-3514628 closes odoo/odoo#139030 X-original-commit: 1727317f258d184432b01b6295d01f688e298257 Signed-off-by: David Monjoie (dmo) Co-authored-by: Nicolas Bayet --- .../static/src/js/editor/odoo-editor/src/OdooEditor.js | 4 ++-- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) 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 8d512de86c5..73fc5159a9a 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 @@ -1923,14 +1923,14 @@ export class OdooEditor extends EventTarget { setContenteditableLink(link) { const editableChildren = link.querySelectorAll('[contenteditable=true]'); - this._stopContenteditable(); - this._fixLinkMutatedElements = { link, wasContenteditableTrue: [...editableChildren], wasContenteditableFalse: [], wasContenteditableNull: [], }; + this._stopContenteditable(); + const contentEditableAttribute = link.getAttribute('contenteditable'); if (contentEditableAttribute === 'true') { this._fixLinkMutatedElements.wasContenteditableTrue.push(link); diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 216dc451c88..600314e6427 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -3201,7 +3201,8 @@ export class Wysiwyg extends Component { * @param {Node} node */ _onPostSanitize(node) { - if (node?.querySelectorAll) { + // _fixLinkMutatedElements check to be removed after the new link edge soltion is merged. + if (node?.querySelectorAll && this.odooEditor && !this.odooEditor._fixLinkMutatedElements) { for (const element of node.querySelectorAll('.o_editable, .o_not_editable')) { const editable = element.classList.contains('o_editable'); if (element.isContentEditable !== editable) {