[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
This commit is contained in:
David Monjoie
2023-02-24 10:06:27 +01:00
parent fa11f330b8
commit 862932d286
@@ -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;