Skip to content

Commit

Permalink
fix: 드래그 한 후 키입력했을 때 제대로 삭제되고 삽입되도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludovico7 committed Nov 27, 2024
1 parent 37348c9 commit f21aef8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions client/src/features/editor/hooks/useBlockOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ export const useBlockOperation = ({
return;
}

if (e.key === "Backspace") {
const isCharacterKey = e.key.length === 1 && !e.ctrlKey && !e.metaKey;

if (e.key === "Backspace" || isCharacterKey) {
e.preventDefault();

const range = selection.getRangeAt(0);
Expand All @@ -152,7 +154,12 @@ export const useBlockOperation = ({
sendCharDeleteOperation(operationNode);
}

block.crdt.currentCaret = startOffset;
if (isCharacterKey) {
const insertOperation = block.crdt.localInsert(startOffset, e.key, block.id, pageId);
sendCharInsertOperation(insertOperation);
}

block.crdt.currentCaret = startOffset + (isCharacterKey ? 1 : 0);
setEditorState({
clock: editorCRDT.clock,
linkedList: editorCRDT.LinkedList,
Expand Down

0 comments on commit f21aef8

Please sign in to comment.