From bb5abc8d80ec09bef4cff691162b5c3e3be49543 Mon Sep 17 00:00:00 2001 From: Rodolpho Lima Date: Fri, 3 Mar 2023 15:45:22 +0000 Subject: [PATCH] [FIX] web_editor: avoid toolbar update if selection outside editable When the selection is outside the editable and the `autohideToolbar` option is false, `_updateToolbar` will perform computations in order to update a toolbar that is not visible. In fact, trying to do so can lead to a traceback, as `getComputedStyle` is called with a null argument when the selection is not contained in the editable. This commit avoids such useless computations and tracebacks by returning from the function when the selection is not inside the editable element. task-3171892 opw-3161789 X-original-commit: d4b13a147f2a69628c050a04655452fcb2e6d759 Part-of: odoo/odoo#115299 --- .../src/js/editor/odoo-editor/src/OdooEditor.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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 e80806b482f..7b07adc4f18 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 @@ -2738,6 +2738,9 @@ export class OdooEditor extends EventTarget { return; } } + if (!this.isSelectionInEditable(sel)) { + return; + } const paragraphDropdownButton = this.toolbar.querySelector('#paragraphDropdownButton'); if (paragraphDropdownButton) { for (const commandState of [ @@ -3614,15 +3617,11 @@ export class OdooEditor extends EventTarget { this.options.onCollaborativeSelectionChange(this.getCurrentCollaborativeSelection()); } } + const isSelectionInEditable = this.isSelectionInEditable(selection); if (!appliedCustomSelection) { - this._updateToolbar(!selection.isCollapsed && this.isSelectionInEditable(selection)); + this._updateToolbar(!selection.isCollapsed && isSelectionInEditable); } - - if ( - !this.editable.contains(selection.anchorNode) && - !this.editable.contains(selection.focusNode) - ) { - // Do not affect selection outside of the editable. + if (!isSelectionInEditable) { return; } // When CTRL+A in the editor, sometimes the browser use the editable