diff --git a/cursor.js b/cursor.js index 84eaf5e..d251ae0 100644 --- a/cursor.js +++ b/cursor.js @@ -90,16 +90,14 @@ export class Cursor { if (key === "ArrowUp" && currentIndex > 0) { const prevSibling = siblings[currentIndex - 1] - const length = prevSibling.textContent.length - const index = length < this.insertIndex ? length : this.insertIndex + const index = Math.max(0, Math.min(prevSibling.textContent.length, this.insertIndex)) this.setTarget(prevSibling, index) // 光标在上一个兄弟元素的起始位置 return } if (key === "ArrowDown" && currentIndex >= 0 && currentIndex < siblings.length - 1) { const nextSibling = siblings[currentIndex + 1] - const length = nextSibling.textContent.length - const index = length < this.insertIndex ? length : this.insertIndex + const index = Math.max(0, Math.min(nextSibling.textContent.length, this.insertIndex)) this.setTarget(nextSibling, index) // 光标在下一个兄弟元素的起始位置 return }