From de4bb254644a1e58bac8cd0a1988a812f94517ec Mon Sep 17 00:00:00 2001 From: Nicolas Bayet Date: Wed, 15 Feb 2023 08:28:57 +0000 Subject: [PATCH] [FIX] web_editor: check if no selection in _handleSelectionInTable Before this commit, if there were no selection in `_handleSelectionInTable` because the document was removed (in case the document was in a removed iframe), the method would crash. task-3052658 closes odoo/odoo#112908 X-original-commit: 8e23a4191730d5512c9de81c23f8e4e88e99ddb1 Signed-off-by: David Monjoie (dmo) --- .../static/src/js/editor/odoo-editor/src/OdooEditor.js | 3 ++- 1 file changed, 2 insertions(+), 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 309e9700477..d3d9e1bbf36 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 @@ -2230,7 +2230,8 @@ export class OdooEditor extends EventTarget { */ _handleSelectionInTable(ev=undefined) { const selection = this.document.getSelection(); - const anchorNode = selection.anchorNode; + // Selection could be gone if the document comes from an iframe that has been removed. + const anchorNode = selection && selection.getRangeAt(0) && selection.anchorNode; if (anchorNode && (closestElement(anchorNode, '[data-oe-protected="true"]') || !ancestors(anchorNode).includes(this.editable))) { return false; }