From 53816a74db6fc29c989530256c1938840166f289 Mon Sep 17 00:00:00 2001 From: Ludovico7 Date: Wed, 27 Nov 2024 21:19:10 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20pageup,=20pagedown=20=EC=BA=90=EB=9F=BF?= =?UTF-8?q?=20=EC=9C=84=EC=B9=98=20=EB=A1=9C=EC=A7=81=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/useMarkdownGrammer.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/src/features/editor/hooks/useMarkdownGrammer.ts b/client/src/features/editor/hooks/useMarkdownGrammer.ts index bd56756d..96b64bfa 100644 --- a/client/src/features/editor/hooks/useMarkdownGrammer.ts +++ b/client/src/features/editor/hooks/useMarkdownGrammer.ts @@ -413,7 +413,10 @@ export const useMarkdownGrammer = ({ const currentCaretPosition = currentBlock.crdt.currentCaret; const headBlock = editorCRDT.LinkedList.getNode(editorCRDT.LinkedList.head); if (!headBlock) return; - headBlock.crdt.currentCaret = currentCaretPosition; + headBlock.crdt.currentCaret = Math.min( + currentCaretPosition, + headBlock.crdt.read().length, + ); editorCRDT.currentBlock = headBlock; setCaretPosition({ blockId: headBlock.id, @@ -432,7 +435,10 @@ export const useMarkdownGrammer = ({ while (lastBlock.next && editorCRDT.LinkedList.getNode(lastBlock.next)) { lastBlock = editorCRDT.LinkedList.getNode(lastBlock.next)!; } - lastBlock.crdt.currentCaret = currentCaretPosition; + lastBlock.crdt.currentCaret = Math.min( + currentCaretPosition, + lastBlock.crdt.read().length, + ); editorCRDT.currentBlock = lastBlock; setCaretPosition({ blockId: lastBlock.id,