From 2ef1ccafa3e52f74c5fb6ae18aafc2ddcdfdb025 Mon Sep 17 00:00:00 2001 From: Ludovico7 Date: Tue, 3 Dec 2024 03:19:10 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=ED=95=9C=EA=B8=80=20=EC=BB=B4?= =?UTF-8?q?=ED=8F=AC=EC=A7=95=EC=8B=9C=20=EC=9C=88=EB=8F=84=EC=9A=B0?= =?UTF-8?q?=EB=8F=84=20=EC=8A=A4=ED=8E=98=EC=9D=B4=EC=8A=A4=EB=B0=94=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=ED=95=98=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: hyonun Co-authored-by: Jang seo yun Co-authored-by: minjungw00 --- client/src/features/editor/Editor.tsx | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/client/src/features/editor/Editor.tsx b/client/src/features/editor/Editor.tsx index 312adff..a369143 100644 --- a/client/src/features/editor/Editor.tsx +++ b/client/src/features/editor/Editor.tsx @@ -224,7 +224,6 @@ export const Editor = ({ onTitleChange, pageId, pageTitle, serializedEditorData blockId: block.id, pageId, }); - sendCharInsertOperation(block.crdt.localInsert(currentCaret + 1, "", block.id, pageId)); block.crdt.currentCaret = currentCaret; } @@ -246,22 +245,19 @@ export const Editor = ({ onTitleChange, pageId, pageTitle, serializedEditorData if (activeElement?.tagName.toLowerCase() === "input") { return; // input에 포커스가 있으면 캐럿 위치 변경하지 않음 } - if (isLocalChange.current || isSameLocalChange.current) { - setCaretPosition({ - blockId: editorCRDT.current.currentBlock.id, - linkedList: editorCRDT.current.LinkedList, - position: editorCRDT.current.currentBlock?.crdt.currentCaret, - pageId, - }); - isLocalChange.current = false; - if (composingCaret.current !== null) { - isSameLocalChange.current = true; - } else { + requestAnimationFrame(() => { + if (isLocalChange.current || isSameLocalChange.current) { + setCaretPosition({ + blockId: editorCRDT.current.currentBlock!.id, + linkedList: editorCRDT.current.LinkedList, + position: editorCRDT.current.currentBlock?.crdt.currentCaret, + pageId, + }); + isLocalChange.current = false; isSameLocalChange.current = false; + return; } - - return; - } + }); // 서윤님 피드백 반영 }, [editorCRDT.current.currentBlock?.id.serialize()]); From 81a9116bc4662870a3f3b1a9f0348572d336013e Mon Sep 17 00:00:00 2001 From: pipisebastian Date: Wed, 4 Dec 2024 00:08:25 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20window=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=ED=95=9C=EA=B8=80=20insert=20=EC=95=88?= =?UTF-8?q?=EB=90=98=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #278 --- client/src/features/editor/Editor.tsx | 59 +++++++++++++++++---------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/client/src/features/editor/Editor.tsx b/client/src/features/editor/Editor.tsx index a369143..06a4c7d 100644 --- a/client/src/features/editor/Editor.tsx +++ b/client/src/features/editor/Editor.tsx @@ -217,17 +217,35 @@ export const Editor = ({ onTitleChange, pageId, pageTitle, serializedEditorData const character = event.data; if (!character) return; - currentCharNode.value = character; - sendCharInsertOperation({ - type: "charInsert", - node: currentCharNode, - blockId: block.id, - pageId, + // 문자열을 개별 문자로 분리 + const characters = Array.from(character); + let currentPosition = currentCaret; + + // 각 문자에 대해 처리 + characters.forEach((char, index) => { + // 현재 위치의 노드 찾기 + const charNode = block.crdt.LinkedList.findByIndex(currentPosition); + if (!charNode) return; + + // 노드 값 설정 및 operation 전송 + charNode.value = char; + sendCharInsertOperation({ + type: "charInsert", + node: charNode, + blockId: block.id, + pageId, + }); + + // 다음 문자를 위한 새 노드 생성 (마지막 문자가 아닌 경우에만) + if (index < characters.length - 1) { + block.crdt.localInsert(currentPosition + 1, "", block.id, pageId); + } + + currentPosition++; }); - block.crdt.currentCaret = currentCaret; + block.crdt.currentCaret = currentCaret + characters.length; } - composingCaret.current = null; if (isSameLocalChange.current) { isSameLocalChange.current = false; @@ -245,20 +263,17 @@ export const Editor = ({ onTitleChange, pageId, pageTitle, serializedEditorData if (activeElement?.tagName.toLowerCase() === "input") { return; // input에 포커스가 있으면 캐럿 위치 변경하지 않음 } - requestAnimationFrame(() => { - if (isLocalChange.current || isSameLocalChange.current) { - setCaretPosition({ - blockId: editorCRDT.current.currentBlock!.id, - linkedList: editorCRDT.current.LinkedList, - position: editorCRDT.current.currentBlock?.crdt.currentCaret, - pageId, - }); - isLocalChange.current = false; - isSameLocalChange.current = false; - return; - } - }); - // 서윤님 피드백 반영 + if (isLocalChange.current || isSameLocalChange.current) { + setCaretPosition({ + blockId: editorCRDT.current.currentBlock!.id, + linkedList: editorCRDT.current.LinkedList, + position: editorCRDT.current.currentBlock?.crdt.currentCaret, + pageId, + }); + isLocalChange.current = false; + isSameLocalChange.current = false; + return; + } }, [editorCRDT.current.currentBlock?.id.serialize()]); useEffect(() => { From cc98b9bddf7f033f8e77d95a74240f82f21c6753 Mon Sep 17 00:00:00 2001 From: pipisebastian Date: Wed, 4 Dec 2024 01:41:07 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=EB=A6=B0=ED=8A=B8=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #278 --- client/src/features/editor/Editor.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/features/editor/Editor.tsx b/client/src/features/editor/Editor.tsx index 06a4c7d..d2a5c60 100644 --- a/client/src/features/editor/Editor.tsx +++ b/client/src/features/editor/Editor.tsx @@ -241,7 +241,7 @@ export const Editor = ({ onTitleChange, pageId, pageTitle, serializedEditorData block.crdt.localInsert(currentPosition + 1, "", block.id, pageId); } - currentPosition++; + currentPosition += 1; }); block.crdt.currentCaret = currentCaret + characters.length;