From d58b28c1dbe47a7a4970b4333c0846fafbf511db Mon Sep 17 00:00:00 2001 From: zhaopeng <41977379+zp190265950@users.noreply.github.com> Date: Sat, 11 May 2024 20:17:24 +0800 Subject: [PATCH] fix: move cursor boundary error with up and down keys #556 --- src/editor/core/event/handlers/keydown/updown.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/editor/core/event/handlers/keydown/updown.ts b/src/editor/core/event/handlers/keydown/updown.ts index f4564de..05b46e2 100644 --- a/src/editor/core/event/handlers/keydown/updown.ts +++ b/src/editor/core/event/handlers/keydown/updown.ts @@ -14,12 +14,13 @@ interface IGetNextPositionIndexPayload { // 根据当前位置索引查找上下行最接近的索引位置 function getNextPositionIndex(payload: IGetNextPositionIndexPayload) { const { positionList, index, isUp, rowNo, cursorX } = payload - let nextIndex = 0 + let nextIndex = -1 // 查找下一行位置列表 const probablePosition: IElementPosition[] = [] if (isUp) { let p = index - 1 - while (p > 0) { + // 等于0的时候上一行是第一行 + while (p >= 0) { const position = positionList[p] p-- if (position.rowNo === rowNo) continue @@ -215,7 +216,7 @@ export function updown(evt: KeyboardEvent, host: CanvasEvent) { isUp, cursorX: curRightX }) - if (!nextIndex) return + if (nextIndex < 0) return // shift则缩放选区 anchorStartIndex = nextIndex anchorEndIndex = nextIndex