From 862932d28687063abc21d93aa0a924d76cc0b5cd Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Wed, 22 Feb 2023 10:34:57 +0000 Subject: [PATCH] [FIX] web_editor: do not traceback on null selection Because the `selectionchange` event is async, the selection can be null if the node has been removed between the moment the selection was moved and the moment the event is triggered. X-original-commit: 3232edb1ccb196c992f75858fe81d08a5af58ab9 Part-of: odoo/odoo#113540 --- .../static/src/js/editor/odoo-editor/src/OdooEditor.js | 6 ++++++ 1 file changed, 6 insertions(+) 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 8b7e6cfd0e9..172d0c92d83 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 @@ -3580,6 +3580,12 @@ export class OdooEditor extends EventTarget { */ _onSelectionChange() { const selection = this.document.getSelection(); + if (!selection) { + // Because the `selectionchange` event is async, the selection can + // be null if the node has been removed between the moment the + // selection was moved and the moment the event is triggered. + return; + } const anchorNode = selection.anchorNode; if (anchorNode && closestElement(anchorNode, '[data-oe-protected="true"]')) { return;