From 10c5a16cd44b8d8e54082df90166f2309dfa788d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Geelen=20=28sge=29?= Date: Wed, 7 Sep 2022 14:08:39 +0000 Subject: [PATCH] [FIX] web_editor: fix ctrl+A selection In some case the ctrl+A selection in the editor create issue with the commands and the toolbar. We fixed it by correcting the selection and force it to be strictly inside the editable. task-2971144 closes odoo/odoo#99718 X-original-commit: be07c2c021c71d1c5654ea5e331287f2d4e0d559 Signed-off-by: David Monjoie (dmo) --- .../js/editor/odoo-editor/src/OdooEditor.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 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 9a1501f268d..50e757f6322 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 @@ -3115,12 +3115,28 @@ export class OdooEditor extends EventTarget { * @private */ _onSelectionChange() { + const selection = this.document.getSelection(); + // 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 + // editable children. Calling `getDeepRange` ensure the selection is + // limited to the editable. + if ( + selection.anchorNode === this.editable && + selection.focusNode === this.editable && + selection.anchorOffset === 0 && + selection.focusOffset === [...this.editable.childNodes].length + ) { + getDeepRange(this.editable, {select: true}); + // The selection is changed in `getDeepRange` and will therefore + // re-trigger the _onSelectionChange. + return; + } + // Compute the current selection on selectionchange but do not record it. Leave // that to the command execution or the 'input' event handler. this._computeHistorySelection(); - const selection = this.document.getSelection(); - if (this._currentMouseState === 'mouseup') { this._fixFontAwesomeSelection(); }