[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/odoo#114583 X-original-commit: f47b306c5f37a43849975e4b7afb2819c80c809e Signed-off-by: David Monjoie (dmo) <dmo@odoo.com> Signed-off-by: Nicolas Bayet <nby@odoo.com>
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user