From 4c453c1a8a97ba67b6534a95e66ad3b050187987 Mon Sep 17 00:00:00 2001 From: Benjamin Vray Date: Mon, 20 Feb 2023 15:27:16 +0000 Subject: [PATCH] [FIX] web_editor: fix traceback when the main element is clicked In the website editor, a traceback error occurs when clicking on the main element since the commit [1]. This is caused by the function '_handleSelectionInTable' calling 'selection.getRangeAt(0)' without checking if there is at least one range in the selection. Steps to reproduce the bug: - Open the website editor and drop a text snippet onto the page. - Click on the snippet to activate it. - Click on the empty area below the snippet, which corresponds to the
element. - A traceback error will appear (if it does not appear, repeat the first three steps multiple times). [1]: https://github.com/odoo/odoo/commit/d977bd64fe88c059c915f9eb0f8029cde65b216a task-3196722 closes odoo/odoo#113383 X-original-commit: 6e79728c7e812458709d3a60ba37dc4c578905b2 Signed-off-by: David Monjoie (dmo) --- .../static/src/js/editor/odoo-editor/src/OdooEditor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4f107a0d24d..8b7e6cfd0e9 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 @@ -2231,7 +2231,7 @@ export class OdooEditor extends EventTarget { _handleSelectionInTable(ev=undefined) { const selection = this.document.getSelection(); // Selection could be gone if the document comes from an iframe that has been removed. - const anchorNode = selection && selection.getRangeAt(0) && selection.anchorNode; + const anchorNode = selection && selection.rangeCount && selection.getRangeAt(0) && selection.anchorNode; if (anchorNode && (closestElement(anchorNode, '[data-oe-protected="true"]') || !ancestors(anchorNode).includes(this.editable))) { return false; }