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 51569561a7a..e80806b482f 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 @@ -73,6 +73,7 @@ import { isVoidElement, cleanZWS, isZWS, + getDeepestPosition, } from './utils/utils.js'; import { editorCommands } from './commands/commands.js'; import { Powerbox } from './powerbox/Powerbox.js'; @@ -1547,26 +1548,34 @@ export class OdooEditor extends EventTarget { _multiselectionDisplayClient({ selection, color, clientId, clientAvatarUrl = '', clientName = this.options._t('Anonymous') }) { let clientRects; - const anchorNode = this.idFind(selection.anchorNodeOid); - const focusNode = this.idFind(selection.focusNodeOid); + let anchorNode = this.idFind(selection.anchorNodeOid); + let focusNode = this.idFind(selection.focusNodeOid); + let anchorOffset = selection.anchorOffset; + let focusOffset = selection.focusOffset; if (!anchorNode || !focusNode) { - return; + anchorNode = this.editable.children[0]; + focusNode = this.editable.children[0]; + anchorOffset = 0; + focusOffset = 0; } + [anchorNode, anchorOffset] = getDeepestPosition(anchorNode, anchorOffset); + [focusNode, focusOffset] = getDeepestPosition(focusNode, focusOffset); + const direction = getCursorDirection( anchorNode, - selection.anchorOffset, + anchorOffset, focusNode, - selection.focusOffset, + focusOffset, ); const range = new Range(); try { if (direction === DIRECTIONS.RIGHT) { - range.setStart(anchorNode, selection.anchorOffset); - range.setEnd(focusNode, selection.focusOffset); + range.setStart(anchorNode, anchorOffset); + range.setEnd(focusNode, focusOffset); } else { - range.setStart(focusNode, selection.focusOffset); - range.setEnd(anchorNode, selection.anchorOffset); + range.setStart(focusNode, focusOffset); + range.setEnd(anchorNode, anchorOffset); } clientRects = Array.from(range.getClientRects()); @@ -3693,13 +3702,17 @@ export class OdooEditor extends EventTarget { getCurrentCollaborativeSelection() { const selection = this._latestComputedSelection || this._computeHistorySelection(); - if (!selection) return; - return Object.assign({ - selection: serializeSelection(selection), + return { + selection: selection ? serializeSelection(selection) : { + anchorNodeOid: undefined, + anchorOffset: undefined, + focusNodeOid: undefined, + focusOffset: undefined, + }, color: this._collabSelectionColor, clientId: this._collabClientId, clientAvatarUrl: this._collabClientAvatarUrl, - }); + }; } clean() {