Skip to content

Commit

Permalink
fix: pageup, pagedown 캐럿 위치 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludovico7 committed Nov 27, 2024
1 parent 464a294 commit 53816a7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions client/src/features/editor/hooks/useMarkdownGrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 53816a7

Please sign in to comment.