Skip to content

Commit

Permalink
feat: 텍스트 입력시, 이전 텍스트에 스타일이 적용되어 있으면 동일한 스타일로 삽입
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludovico7 committed Nov 26, 2024
1 parent 835b7cb commit a734289
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions client/src/features/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,34 @@ export const Editor = ({ onTitleChange, pageId, pageTitle, serializedEditorData
charNode = block.crdt.localInsert(0, addedChar, block.id, pageId);
} else if (caretPosition > currentContent.length) {
// 맨 뒤에 삽입
const prevChar = editorCRDT.current.currentBlock?.crdt.LinkedList.findByIndex(
currentContent.length - 1,
);
const addedChar = newContent[newContent.length - 1];
charNode = block.crdt.localInsert(currentContent.length, addedChar, block.id, pageId);
charNode = block.crdt.localInsert(
currentContent.length,
addedChar,
block.id,
pageId,
prevChar?.style,
prevChar?.color,
prevChar?.backgroundColor,
);
} else {
// 중간에 삽입
const prevChar = editorCRDT.current.currentBlock?.crdt.LinkedList.findByIndex(
validCaretPosition - 1,
);
const addedChar = newContent[validCaretPosition - 1];
charNode = block.crdt.localInsert(validCaretPosition - 1, addedChar, block.id, pageId);
charNode = block.crdt.localInsert(
validCaretPosition - 1,
addedChar,
block.id,
pageId,
prevChar?.style,
prevChar?.color,
prevChar?.backgroundColor,
);
}
editorCRDT.current.currentBlock!.crdt.currentCaret = caretPosition;
sendCharInsertOperation({ node: charNode.node, blockId: block.id, pageId });
Expand Down

0 comments on commit a734289

Please sign in to comment.