yorkie-js-sdk icon indicating copy to clipboard operation
yorkie-js-sdk copied to clipboard

`Selection` of clients should be shared as `presence`.

Open Eithea opened this issue 1 year ago • 0 comments

Description:

export class CRDTText extends CRDTTextElement {
  private onChangesHandler?: (changes: Array<TextChange>) => void;
  private rgaTreeSplit: RGATreeSplit<string>;
  private selectionMap: Map<string, Selection>;
  ...
function toText(text: CRDTText): PbJSONElement {
  const pbText = new PbJSONElement.Text();
  pbText.setNodesList(toTextNodes(text.getRGATreeSplit()));
  pbText.setCreatedAt(toTimeTicket(text.getCreatedAt()));
  pbText.setMovedAt(toTimeTicket(text.getMovedAt()));
  pbText.setRemovedAt(toTimeTicket(text.getRemovedAt()));

  const pbElement = new PbJSONElement();
  pbElement.setText(pbText);
  return pbElement;
}

CRDTText object has selectionMap which records the Selection of each peer, but it is lost in the API conversion. (the converters toText do not handle it.) The selections of client do not need to be stored, but it should be shared as presence between activated clients.

Why:

By changing it sharable, we solve some problems :

  • A newly connected client cannot see cursors until each existing peer makes a new edit.
  • Remote cursors are not updated when a client receives snapshot.

Eithea avatar Aug 05 '22 10:08 Eithea