Skip to content

Commit

Permalink
Remove splitLevels from Tree.Edit
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Nov 20, 2023
1 parent 81a4a7a commit 4251c59
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 146 deletions.
9 changes: 5 additions & 4 deletions public/prosemirror.html
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,11 @@ <h2>Yorkie.Tree</h2>
openEnd &&
structure
) {
root.tree.edit(from, to, docToTreeNode(node.toJSON()), [
openStart,
openEnd,
]);
// TODO(hackerwins): edit should support openStart and openEnd.
// root.tree.edit(from, to, docToTreeNode(node.toJSON()), [
// openStart,
// openEnd,
// ]);
continue;
}

Expand Down
18 changes: 3 additions & 15 deletions src/document/crdt/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,6 @@ export class CRDTTree extends CRDTGCElement {
public findNodesAndSplit(
pos: CRDTTreePos,
editedAt: TimeTicket,
/* eslint-disable @typescript-eslint/no-unused-vars */
splitLevel = 0,
): [CRDTTreeNode, CRDTTreeNode] {
// 01. Find the parent and left sibling node of the given position.
const [parent, leftSibling] = pos.toTreeNodes(this);
Expand Down Expand Up @@ -719,21 +717,12 @@ export class CRDTTree extends CRDTGCElement {
public edit(
range: [CRDTTreePos, CRDTTreePos],
contents: Array<CRDTTreeNode> | undefined,
splitLevels: [number, number],
editedAt: TimeTicket,
latestCreatedAtMapByActor?: Map<string, TimeTicket>,
): [Array<TreeChange>, Map<string, TimeTicket>] {
// 01. split text nodes at the given range if needed.
const [fromParent, fromLeft] = this.findNodesAndSplit(
range[0],
editedAt,
splitLevels[0],
);
const [toParent, toLeft] = this.findNodesAndSplit(
range[1],
editedAt,
splitLevels[1],
);
const [fromParent, fromLeft] = this.findNodesAndSplit(range[0], editedAt);
const [toParent, toLeft] = this.findNodesAndSplit(range[1], editedAt);

// TODO(hackerwins): If concurrent deletion happens, we need to seperate the
// range(from, to) into multiple ranges.
Expand Down Expand Up @@ -856,12 +845,11 @@ export class CRDTTree extends CRDTGCElement {
public editT(
range: [number, number],
contents: Array<CRDTTreeNode> | undefined,
splitLevels: [number, number],
editedAt: TimeTicket,
): void {
const fromPos = this.findPos(range[0]);
const toPos = this.findPos(range[1]);
this.edit([fromPos, toPos], contents, splitLevels, editedAt);
this.edit([fromPos, toPos], contents, editedAt);
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/document/json/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ export class Tree {
crdtNodes.length
? crdtNodes.map((crdtNode) => crdtNode?.deepcopy())
: undefined,
[0, 0],
ticket,
);

Expand Down
1 change: 0 additions & 1 deletion src/document/operation/tree_edit_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export class TreeEditOperation extends Operation {
const [changes] = tree.edit(
[this.fromPos, this.toPos],
this.contents?.map((content) => content.deepcopy()),
[0, 0],
this.getExecutedAt(),
this.maxCreatedAtMapByActor,
);
Expand Down
Loading

0 comments on commit 4251c59

Please sign in to comment.