[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) <dmo@odoo.com>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user