Skip to content

Commit

Permalink
Apply new naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Jul 19, 2023
1 parent 5546fa4 commit 9329a6f
Show file tree
Hide file tree
Showing 18 changed files with 185 additions and 229 deletions.
71 changes: 38 additions & 33 deletions public/prosemirror.html
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,13 @@ <h2>Yorkie.RGASplit</h2>
selection: transaction.curSelection,
});

doc.update((root) => {
root.selection = root.tree.toPosRange([
transaction.curSelection.from,
transaction.curSelection.to,
]);
doc.update((root, presence) => {
presence.set({
selection: root.tree.toPosRange([
transaction.curSelection.from,
transaction.curSelection.to,
]),
});
});
printLog();
return;
Expand All @@ -338,7 +340,7 @@ <h2>Yorkie.RGASplit</h2>
transaction: transaction,
});

doc.update((root) => {
doc.update((root, presence) => {
for (const step of transaction.steps) {
const {
jsonID: stepType,
Expand All @@ -354,7 +356,7 @@ <h2>Yorkie.RGASplit</h2>
// TODO(hackerwins): replaceAround replaces the given range with given gap.
if (stepType === 'replaceAround') {
root.tree.move(from, to, gapFrom, gapTo);
return;
continue;
}

// 02-2. Enter Key: Insert Paragraph
Expand All @@ -366,13 +368,13 @@ <h2>Yorkie.RGASplit</h2>
) {
// TODO(hackerwins): Figure out how many depth to split.
root.tree.split(from, 2);
return;
continue;
}

// 02-1. Delete the given range.
if (!content.content.length) {
root.tree.edit(from, to);
return;
continue;
}

// 03-4. Edit: Insert the given content.
Expand All @@ -381,15 +383,30 @@ <h2>Yorkie.RGASplit</h2>
}
}

root.selection = root.tree.toPosRange([
transaction.curSelection.from,
transaction.curSelection.to,
]);
presence.set({
selection: root.tree.toPosRange([
transaction.curSelection.from,
transaction.curSelection.to,
]),
});
});
printLog();
},
});

doc.subscribe('others', (event) => {
if (event.type === 'presence-changed') {
const { clientID, presence } = event.value;
displayRemoteSelection(
view,
doc.getRoot().tree,
presence.selection[0],
presence.selection[1],
clientID,
);
}
});

// 03. Downstream: yorkie.Tree to ProseMirror.
doc.subscribe((event) => {
if (event.type !== 'remote-change') {
Expand All @@ -402,32 +419,20 @@ <h2>Yorkie.RGASplit</h2>
let toPos = -1;
for (const op of operations) {
if (op.type !== 'tree-edit') {
if (
op.type === 'set' &&
op.path === '$' &&
op.key === 'selection'
) {
const selection = doc.getRoot().selection;
displayRemoteSelection(
view,
root.tree,
selection[0],
selection[1],
actor,
);
}
continue;
}
const { from, to, value: content } = op;
const { from, to, value: contents } = op;
const transform = view.state.tr;
if (content) {
if (contents) {
transform.replaceWith(
from,
to,
Node.fromJSON(mySchema, {
type: content.type,
text: content.value,
}),
...contents.map((content) =>
Node.fromJSON(mySchema, {
type: content.type,
text: content.value,
}),
),
);
} else {
transform.replace(from, to);
Expand Down
10 changes: 5 additions & 5 deletions src/api/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
RGATreeSplit,
RGATreeSplitNode,
RGATreeSplitNodeID,
RGATreeSplitNodePos,
RGATreeSplitPos,
} from '@yorkie-js-sdk/src/document/crdt/rga_tree_split';
import { CRDTText, CRDTTextValue } from '@yorkie-js-sdk/src/document/crdt/text';
import {
Expand Down Expand Up @@ -248,7 +248,7 @@ function toTextNodeID(id: RGATreeSplitNodeID): PbTextNodeID {
/**
* `toTextNodePos` converts the given model to Protobuf format.
*/
function toTextNodePos(pos: RGATreeSplitNodePos): PbTextNodePos {
function toTextNodePos(pos: RGATreeSplitPos): PbTextNodePos {
const pbTextNodePos = new PbTextNodePos();
pbTextNodePos.setCreatedAt(toTimeTicket(pos.getID().getCreatedAt()));
pbTextNodePos.setOffset(pos.getID().getOffset());
Expand Down Expand Up @@ -521,7 +521,7 @@ function toTextNodes(
function toTreeNodesWhenEdit(nodes: Array<CRDTTreeNode>): Array<PbTreeNodes> {
const pbTreeNodesList: Array<PbTreeNodes> = [];

if (!nodes.length) {
if (!nodes || !nodes.length) {
return pbTreeNodesList;
}

Expand Down Expand Up @@ -863,8 +863,8 @@ function fromElementSimple(pbElementSimple: PbJSONElementSimple): CRDTElement {
/**
* `fromTextNodePos` converts the given Protobuf format to model format.
*/
function fromTextNodePos(pbTextNodePos: PbTextNodePos): RGATreeSplitNodePos {
return RGATreeSplitNodePos.of(
function fromTextNodePos(pbTextNodePos: PbTextNodePos): RGATreeSplitPos {
return RGATreeSplitPos.of(
RGATreeSplitNodeID.of(
fromTimeTicket(pbTextNodePos.getCreatedAt())!,
pbTextNodePos.getOffset(),
Expand Down
Loading

0 comments on commit 9329a6f

Please sign in to comment.