Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/#278 캐럿이 계속 튀는 문제 #280

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions client/src/features/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +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 += 1;
});
sendCharInsertOperation(block.crdt.localInsert(currentCaret + 1, "", block.id, pageId));

block.crdt.currentCaret = currentCaret;
block.crdt.currentCaret = currentCaret + characters.length;
}

composingCaret.current = null;
if (isSameLocalChange.current) {
isSameLocalChange.current = false;
Expand All @@ -248,21 +265,15 @@ export const Editor = ({ onTitleChange, pageId, pageTitle, serializedEditorData
}
if (isLocalChange.current || isSameLocalChange.current) {
setCaretPosition({
blockId: editorCRDT.current.currentBlock.id,
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 {
isSameLocalChange.current = false;
}

isSameLocalChange.current = false;
return;
}
// 서윤님 피드백 반영
}, [editorCRDT.current.currentBlock?.id.serialize()]);

useEffect(() => {
Expand Down
Loading