From 07a14839671ee516db124b18f5b58d6ad08f382d Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Thu, 8 Sep 2022 13:53:40 +0000 Subject: [PATCH] [FIX] web_editor: do not affect selection outside of the editable Unfortunately, the selectionchange event is triggered on document, so we need to be careful not to affect the selection if it is not in the editable. Part-of: odoo/odoo#99896 --- .../static/src/js/editor/odoo-editor/src/OdooEditor.js | 7 +++++++ 1 file changed, 7 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 b398b7a2463..076a4b16dbf 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 @@ -3116,6 +3116,13 @@ export class OdooEditor extends EventTarget { */ _onSelectionChange() { const selection = this.document.getSelection(); + if ( + !this.editable.contains(selection.anchorNode) && + !this.editable.contains(selection.focusNode) + ) { + // Do not affect selection outside of the editable. + return; + } // When CTRL+A in the editor, sometimes the browser use the editable // element as an anchor & focus node. This is an issue for the commands // and the toolbar so we need to fix the selection to be based on the