Skip to content

Commit

Permalink
변경사항 저장
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludovico7 committed Nov 20, 2024
1 parent 1f7f8f8 commit c01f779
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
33 changes: 16 additions & 17 deletions @noctaCrdt/LinkedList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export abstract class LinkedList<T extends Node<NodeId>> {
}

getNode(id: T["id"] | null): T | null {
console.log("id확인", id);
if (!id) return null;
return this.nodeMap[JSON.stringify(id)] || null;
}
Expand Down Expand Up @@ -150,7 +149,7 @@ export abstract class LinkedList<T extends Node<NodeId>> {
insertAtIndex(index: number, value: string, id: T["id"]): InsertOperation {
try {
const node = this.createNode(value, id);
// this.setNode(id, node);
this.setNode(id, node);

if (!this.head || index <= 0) {
node.next = this.head;
Expand All @@ -163,22 +162,21 @@ export abstract class LinkedList<T extends Node<NodeId>> {
}

this.head = id;
} else {
const prevNode = this.findByIndex(index - 1);
const nextNodeId = prevNode.next;

node.next = nextNodeId;
node.prev = prevNode.id;
prevNode.next = id;

if (nextNodeId) {
const nextNode = this.getNode(nextNodeId);
if (nextNode) {
nextNode.prev = id;
}
return { node };
}

const prevNode = this.findByIndex(index - 1);
node.next = prevNode.next;
prevNode.next = id;
node.prev = prevNode.id;

if (node.next) {
const nextNode = this.getNode(node.next);
if (nextNode) {
nextNode.prev = id;
}
}
this.setNode(id, node);

return { node };
} catch (e) {
throw new Error(`InsertAtIndex failed: ${e}`);
Expand Down Expand Up @@ -254,8 +252,9 @@ export abstract class LinkedList<T extends Node<NodeId>> {
break;
}
result.push(currentNode!);
currentNodeId = currentNode.next;
prevNodeId = currentNodeId;
currentNodeId = currentNode.next;

console.log("new currentNodeId", currentNodeId);
if (count == 10) {
break;
Expand Down
1 change: 1 addition & 0 deletions client/src/features/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const Editor = ({ onTitleChange, pageId, serializedEditorData }: EditorPr
linkedList: editorCRDT.current.LinkedList,
currentBlock: null as BlockId | null,
});
console.log("clock", editorCRDT.current.clock);

const { sensors, handleDragEnd } = useBlockDragAndDrop({
editorCRDT: editorCRDT.current,
Expand Down
2 changes: 1 addition & 1 deletion client/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

0 comments on commit c01f779

Please sign in to comment.