From 2c84ff74f744bdefe5c61b44fa7d3b226924ea47 Mon Sep 17 00:00:00 2001 From: abd-msyukyu-odoo Date: Fri, 14 Jul 2023 12:12:20 +0000 Subject: [PATCH] [FIX] web_editor: scope getFurthestUneditableParent in editable This commit fixes the method so that it is not allowed to probe outside the boundaries of the `root` editable element, no matter the value of `parentLimit`. This also allows to not specify `parentLimit` (becomes the editable element by default). task-3425395 X-original-commit: ffeb1abcc675dd05fb9546e39aac4498e510bbbc Part-of: odoo/odoo#128631 --- .../static/src/js/editor/odoo-editor/src/utils/utils.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 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 9da0f6c79dd..00b6b4f6679 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 @@ -262,19 +262,22 @@ export function findNode(domPath, findCallback = () => true, stopCallback = () = * the range (so that it is not possible to partially remove them) * * @param {Node} node - * @param {Node} parentLimit non-inclusive furthest parent allowed + * @param {Node} [parentLimit=undefined] non-inclusive furthest parent allowed * @returns {Node} uneditable parent if it exists */ export function getFurthestUneditableParent(node, parentLimit) { - if (node === parentLimit || !parentLimit.contains(node)) { + if (node === parentLimit || (parentLimit && !parentLimit.contains(node))) { return undefined; } let parent = node && node.parentElement; let nonEditableElement; - while (parent && parent !== parentLimit) { + while (parent && (!parentLimit || parent !== parentLimit)) { if (!parent.isContentEditable) { nonEditableElement = parent; } + if (parent.oid === "root") { + break; + } parent = parent.parentElement; } return nonEditableElement;