[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
This commit is contained in:
Rodolpho Lima
2023-03-15 16:08:17 +01:00
parent a03549d771
commit bb5abc8d80
@@ -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