From 78dec0b378dd8152fc62ceafce7a064c50634d63 Mon Sep 17 00:00:00 2001 From: Lucas Perais Date: Tue, 27 Jun 2023 10:01:59 +0000 Subject: [PATCH] [FIX] web_editor: OdooEditor and wysiwyg don't hint inside t-fields Before this commit, when typing "/" inside a node that had a t-field attrbute the OdooEditor displayed its hint in order to spawn the Powerbox. This is not ideal as the content of a t-field is rather irrelevant. After tis commit, a t-field node behaves like a t-out: there is no hinting inside them Part-of: odoo/odoo#128228 --- .../static/src/js/editor/odoo-editor/src/OdooEditor.js | 2 +- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 6 +++++- 2 files changed, 6 insertions(+), 2 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 b0063384890..5241c0b178b 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 @@ -4106,7 +4106,7 @@ export class OdooEditor extends EventTarget { if ( block && (content === '' || content === '
') && - !block.querySelector('T[t-out]') && + !block.querySelector('T[t-out],[t-field]') && ancestors(block, this.editable).includes(this.editable) ) { this.observerUnactive(); diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 7ab96d3f4b5..9df568691dc 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -354,7 +354,7 @@ export class Wysiwyg extends Component { getPowerboxElement: () => { const selection = (this.options.document || document).getSelection(); if (selection.isCollapsed && selection.rangeCount) { - const baseNode = closestElement(selection.anchorNode, 'P, DIV'); + const baseNode = closestElement(selection.anchorNode, 'P:not([t-field]), DIV:not([t-field])'); const fieldContainer = closestElement(selection.anchorNode, '[data-oe-field]'); if (!baseNode || ( @@ -1219,9 +1219,13 @@ export class Wysiwyg extends Component { $odooFields.each((i, field) => { const observer = new MutationObserver((mutations) => { mutations = this.odooEditor.filterMutationRecords(mutations); + mutations = mutations.filter(rec => + !(rec.type === "attributes" && (rec.attributeName.startsWith("data-oe-t"))) + ); if (!mutations.length) { return; } + let $node = $(field); // Do not forward "unstyled" copies to other nodes. if ($node.hasClass('o_translation_without_style')) {