Skip to content

Commit 6917fe1

Browse files
committed
feat: setCaretPosition 함수 안쓰는 linkedList 제거
#2
1 parent ff1d422 commit 6917fe1

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

client/src/features/editor/Editor.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ export const Editor = ({
276276
if (isLocalChange.current || isSameLocalChange.current) {
277277
setCaretPosition({
278278
blockId: editorCRDT.current.currentBlock!.id,
279-
linkedList: editorCRDT.current.LinkedList,
280279
position: editorCRDT.current.currentBlock?.crdt.currentCaret,
281280
pageId,
282281
});
@@ -422,7 +421,7 @@ export const Editor = ({
422421
</SortableContext>
423422
</DndContext>
424423
{editorState.linkedList.spread().length === 0 && (
425-
<div data-testId="addNewBlockButton" className={addNewBlockButton} onClick={addNewBlock}>
424+
<div data-testid="addNewBlockButton" className={addNewBlockButton} onClick={addNewBlock}>
426425
클릭해서 새로운 블록을 추가하세요
427426
</div>
428427
)}

client/src/features/editor/hooks/useMarkdownGrammer.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export const useMarkdownGrammer = ({
270270
editorCRDT.currentBlock = targetBlock;
271271
setCaretPosition({
272272
blockId: targetBlock.id,
273-
linkedList: editorCRDT.LinkedList,
273+
274274
position: targetBlock.crdt.read().length,
275275
pageId,
276276
});
@@ -437,7 +437,7 @@ export const useMarkdownGrammer = ({
437437
currentBlock.crdt.currentCaret = e.key === "Home" ? 0 : currentBlock.crdt.read().length;
438438
setCaretPosition({
439439
blockId: currentBlock.id,
440-
linkedList: editorCRDT.LinkedList,
440+
441441
position: currentBlock.crdt.currentCaret,
442442
pageId,
443443
});
@@ -456,7 +456,7 @@ export const useMarkdownGrammer = ({
456456
editorCRDT.currentBlock = headBlock;
457457
setCaretPosition({
458458
blockId: headBlock.id,
459-
linkedList: editorCRDT.LinkedList,
459+
460460
position: currentCaretPosition,
461461
pageId,
462462
});
@@ -478,7 +478,7 @@ export const useMarkdownGrammer = ({
478478
editorCRDT.currentBlock = lastBlock;
479479
setCaretPosition({
480480
blockId: lastBlock.id,
481-
linkedList: editorCRDT.LinkedList,
481+
482482
position: currentCaretPosition,
483483
pageId,
484484
});
@@ -516,7 +516,7 @@ export const useMarkdownGrammer = ({
516516
editorCRDT.currentBlock = targetBlock;
517517
setCaretPosition({
518518
blockId: targetBlock.id,
519-
linkedList: editorCRDT.LinkedList,
519+
520520
position: Math.min(caretPosition, targetBlock.crdt.read().length),
521521
pageId,
522522
});
@@ -547,7 +547,7 @@ export const useMarkdownGrammer = ({
547547
editorCRDT.currentBlock = targetBlock;
548548
setCaretPosition({
549549
blockId: targetBlock.id,
550-
linkedList: editorCRDT.LinkedList,
550+
551551
position: targetBlock.crdt.read().length,
552552
pageId,
553553
});
@@ -573,7 +573,7 @@ export const useMarkdownGrammer = ({
573573
editorCRDT.currentBlock = targetBlock;
574574
setCaretPosition({
575575
blockId: targetBlock.id,
576-
linkedList: editorCRDT.LinkedList,
576+
577577
position: 0,
578578
pageId,
579579
});

client/src/utils/caretUtils.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { BlockId } from "@noctaCrdt/NodeId";
33

44
interface SetCaretPositionProps {
55
blockId: BlockId;
6-
linkedList: BlockLinkedList | TextLinkedList;
76
clientX?: number;
87
clientY?: number;
98
position?: number; // Used to set the caret at a specific position
@@ -72,12 +71,7 @@ export const getAbsoluteCaretPosition = (element: HTMLElement): number => {
7271
return 0;
7372
};
7473

75-
export const setCaretPosition = ({
76-
blockId,
77-
linkedList,
78-
position,
79-
pageId,
80-
}: SetCaretPositionProps): void => {
74+
export const setCaretPosition = ({ blockId, position, pageId }: SetCaretPositionProps): void => {
8175
try {
8276
if (position === undefined) return;
8377
const selection = window.getSelection();

0 commit comments

Comments
 (0)