[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
This commit is contained in:
Lucas Perais
2023-07-20 17:01:31 +02:00
parent be45ee3b92
commit 78dec0b378
2 changed files with 6 additions and 2 deletions
@@ -4106,7 +4106,7 @@ export class OdooEditor extends EventTarget {
if (
block &&
(content === '' || content === '<br>') &&
!block.querySelector('T[t-out]') &&
!block.querySelector('T[t-out],[t-field]') &&
ancestors(block, this.editable).includes(this.editable)
) {
this.observerUnactive();
@@ -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')) {