fix: move cursor boundary error with up and down keys #556

pr675
zhaopeng 2 years ago committed by GitHub
parent 73e47f56b5
commit d58b28c1db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -14,12 +14,13 @@ interface IGetNextPositionIndexPayload {
// 根据当前位置索引查找上下行最接近的索引位置 // 根据当前位置索引查找上下行最接近的索引位置
function getNextPositionIndex(payload: IGetNextPositionIndexPayload) { function getNextPositionIndex(payload: IGetNextPositionIndexPayload) {
const { positionList, index, isUp, rowNo, cursorX } = payload const { positionList, index, isUp, rowNo, cursorX } = payload
let nextIndex = 0 let nextIndex = -1
// 查找下一行位置列表 // 查找下一行位置列表
const probablePosition: IElementPosition[] = [] const probablePosition: IElementPosition[] = []
if (isUp) { if (isUp) {
let p = index - 1 let p = index - 1
while (p > 0) { // 等于0的时候上一行是第一行
while (p >= 0) {
const position = positionList[p] const position = positionList[p]
p-- p--
if (position.rowNo === rowNo) continue if (position.rowNo === rowNo) continue
@ -215,7 +216,7 @@ export function updown(evt: KeyboardEvent, host: CanvasEvent) {
isUp, isUp,
cursorX: curRightX cursorX: curRightX
}) })
if (!nextIndex) return if (nextIndex < 0) return
// shift则缩放选区 // shift则缩放选区
anchorStartIndex = nextIndex anchorStartIndex = nextIndex
anchorEndIndex = nextIndex anchorEndIndex = nextIndex

Loading…
Cancel
Save