[FIX] web_editor: prevent edition on void elements

Before this commit, it was possible to edit void element if they were
branded. It does not make sense to edit a void element.

task-3096813

X-original-commit: fbf633b8110a74dbf25bdc5372a60e793017fbdc
Part-of: odoo/odoo#110513
This commit is contained in:
Nicolas Bayet
2023-01-20 11:43:50 +01:00
parent bcf6f6625b
commit 4562b4ad69
4 changed files with 9 additions and 3 deletions
@@ -70,6 +70,7 @@ import {
parseHTML,
splitTextNode,
isEditorTab,
isVoidElement
} from './utils/utils.js';
import { editorCommands } from './commands/commands.js';
import { Powerbox } from './powerbox/Powerbox.js';
@@ -2161,7 +2162,8 @@ export class OdooEditor extends EventTarget {
this.observerUnactive('_activateContenteditable');
this.editable.setAttribute('contenteditable', this.options.isRootEditable);
for (const node of this.options.getContentEditableAreas(this)) {
const editableAreas = this.options.getContentEditableAreas(this).filter(node => !isVoidElement(node));
for (const node of editableAreas) {
if (!node.isContentEditable) {
node.setAttribute('contenteditable', true);
}
@@ -18,6 +18,7 @@ import {
isZWS,
getUrlsInfosInString,
URL_REGEX,
isVoidElement,
} from './utils.js';
const NOT_A_NUMBER = /[^\d]/g;
@@ -219,7 +220,7 @@ class Sanitize {
// Ensure elements which should not contain any content are tagged
// contenteditable=false to avoid any hiccup.
if (
(isMediaElement(node) || node.tagName === 'HR') &&
isVoidElement(node) &&
node.getAttribute('contenteditable') !== 'false'
) {
node.setAttribute('contenteditable', 'false');
@@ -1351,6 +1351,9 @@ export function isMediaElement(node) {
(node.classList.contains('o_image') || node.classList.contains('media_iframe_video')))
);
}
export function isVoidElement(node) {
return isMediaElement(node) || node.tagName === 'HR';
}
export function containsUnremovable(node) {
if (!node) {
@@ -399,7 +399,7 @@ describe('Link', () => {
}, {
isRootEditable: false,
getContentEditableAreas: function (editor) {
return editor.editable.querySelectorAll('a span');
return [...editor.editable.querySelectorAll('a span')];
}
});
});