From 9b60a1bfc14c083ddadb9ad3201e846009569d59 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Tue, 11 Oct 2022 08:33:59 +0000 Subject: [PATCH] [FIX] web_editor: prevent deleting content outside the editable area When checking whether an element was removable or not, we failed to check whether it was within the editable area. As a result it was sometimes possible to accidentally delete something outside of it. To reproduce the bug, insert a link in a blank editor, then press delete repeatedly until the whole link is gone, and then one more time. This deleted an element from Odoo's UI. task-2993740 closes odoo/odoo#104268 X-original-commit: 55e4e0577ac8a62d57f759572b8a5e608c7582b2 Signed-off-by: David Monjoie (dmo) --- .../static/src/js/editor/odoo-editor/src/utils/utils.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js index fd357e061b9..1efe2f45624 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js @@ -1337,14 +1337,13 @@ export function isUnbreakable(node) { } export function isUnremovable(node) { - if (node.nodeType !== Node.ELEMENT_NODE && node.nodeType !== Node.TEXT_NODE) { - return true; - } return ( + (node.nodeType !== Node.ELEMENT_NODE && node.nodeType !== Node.TEXT_NODE) || node.oid === 'root' || (node.nodeType === Node.ELEMENT_NODE && (node.classList.contains('o_editable') || node.getAttribute('t-set') || node.getAttribute('t-call'))) || - (node.classList && node.classList.contains('oe_unremovable')) + (node.classList && node.classList.contains('oe_unremovable')) || + (node.ownerDocument && node.ownerDocument.defaultWindow && !ancestors(node).find(ancestor => ancestor.oid === 'root')) // Node is in DOM but not in editable. ); }