From f21aef8e556d948fecf341357ebd3bfb6625bc68 Mon Sep 17 00:00:00 2001 From: Ludovico7 Date: Wed, 27 Nov 2024 17:45:06 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=93=9C=EB=9E=98=EA=B7=B8=20=ED=95=9C?= =?UTF-8?q?=20=ED=9B=84=20=ED=82=A4=EC=9E=85=EB=A0=A5=ED=96=88=EC=9D=84=20?= =?UTF-8?q?=EB=95=8C=20=EC=A0=9C=EB=8C=80=EB=A1=9C=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=EB=90=98=EA=B3=A0=20=EC=82=BD=EC=9E=85=EB=90=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/features/editor/hooks/useBlockOperation.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/client/src/features/editor/hooks/useBlockOperation.ts b/client/src/features/editor/hooks/useBlockOperation.ts index 18f08547..cff98159 100644 --- a/client/src/features/editor/hooks/useBlockOperation.ts +++ b/client/src/features/editor/hooks/useBlockOperation.ts @@ -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); @@ -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,