Skip to content

Commit f47b306

Browse files
committed
[FIX] web_editor: show a default selection in collaboration
Before this commit, whenever a peer had no selection in the editor, no selection would appear to the other collaborators. It was therefore visually impossible to know excaltly to how many people someone is connected. Now, we set the default selection to be in the first node of the document. Additionnaly, some selection were not displayed because the call to `getClientRects` did not return any rect. By creating a deep range through the use of `getDeepestPosition`, we ensure to retrieve the selection rect. task-3217719 closes odoo#114481 Signed-off-by: David Monjoie (dmo) <dmo@odoo.com> Signed-off-by: Nicolas Bayet <nby@odoo.com>
1 parent 8396878 commit f47b306

File tree

1 file changed

+26
-13
lines changed
  • addons/web_editor/static/src/js/editor/odoo-editor/src

1 file changed

+26
-13
lines changed

addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import {
7272
isVoidElement,
7373
cleanZWS,
7474
isZWS,
75+
getDeepestPosition,
7576
} from './utils/utils.js';
7677
import { editorCommands } from './commands/commands.js';
7778
import { Powerbox } from './powerbox/Powerbox.js';
@@ -1562,26 +1563,34 @@ export class OdooEditor extends EventTarget {
15621563
_multiselectionDisplayClient({ selection, color, clientId, clientAvatarUrl = '', clientName = this.options._t('Anonymous') }) {
15631564
let clientRects;
15641565

1565-
const anchorNode = this.idFind(selection.anchorNodeOid);
1566-
const focusNode = this.idFind(selection.focusNodeOid);
1566+
let anchorNode = this.idFind(selection.anchorNodeOid);
1567+
let focusNode = this.idFind(selection.focusNodeOid);
1568+
let anchorOffset = selection.anchorOffset;
1569+
let focusOffset = selection.focusOffset;
15671570
if (!anchorNode || !focusNode) {
1568-
return;
1571+
anchorNode = this.editable.children[0];
1572+
focusNode = this.editable.children[0];
1573+
anchorOffset = 0;
1574+
focusOffset = 0;
15691575
}
15701576

1577+
[anchorNode, anchorOffset] = getDeepestPosition(anchorNode, anchorOffset);
1578+
[focusNode, focusOffset] = getDeepestPosition(focusNode, focusOffset);
1579+
15711580
const direction = getCursorDirection(
15721581
anchorNode,
1573-
selection.anchorOffset,
1582+
anchorOffset,
15741583
focusNode,
1575-
selection.focusOffset,
1584+
focusOffset,
15761585
);
15771586
const range = new Range();
15781587
try {
15791588
if (direction === DIRECTIONS.RIGHT) {
1580-
range.setStart(anchorNode, selection.anchorOffset);
1581-
range.setEnd(focusNode, selection.focusOffset);
1589+
range.setStart(anchorNode, anchorOffset);
1590+
range.setEnd(focusNode, focusOffset);
15821591
} else {
1583-
range.setStart(focusNode, selection.focusOffset);
1584-
range.setEnd(anchorNode, selection.anchorOffset);
1592+
range.setStart(focusNode, focusOffset);
1593+
range.setEnd(anchorNode, anchorOffset);
15851594
}
15861595

15871596
clientRects = Array.from(range.getClientRects());
@@ -3655,13 +3664,17 @@ export class OdooEditor extends EventTarget {
36553664

36563665
getCurrentCollaborativeSelection() {
36573666
const selection = this._latestComputedSelection || this._computeHistorySelection();
3658-
if (!selection) return;
3659-
return Object.assign({
3660-
selection: serializeSelection(selection),
3667+
return {
3668+
selection: selection ? serializeSelection(selection) : {
3669+
anchorNodeOid: undefined,
3670+
anchorOffset: undefined,
3671+
focusNodeOid: undefined,
3672+
focusOffset: undefined,
3673+
},
36613674
color: this._collabSelectionColor,
36623675
clientId: this._collabClientId,
36633676
clientAvatarUrl: this._collabClientAvatarUrl,
3664-
});
3677+
};
36653678
}
36663679

36673680
clean() {

0 commit comments

Comments
 (0)