Skip to content

Commit

Permalink
Fix moveVertically when the target position falls outside the viewport
Browse files Browse the repository at this point in the history
FIX: Fix a bug that caused `EditorView.moveVertically` to only move by one line, even when
given a custom distance, in some cases.

Closes codemirror/dev#523
  • Loading branch information
marijnh committed Jun 24, 2021
1 parent ad166f8 commit 7542a04
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,10 @@ export function moveVertically(view: EditorView, start: SelectionRange, forward:
} else {
goalCol = Math.round(goal / view.defaultCharacterWidth)
}
if (dir < 0 && line.from == 0) return EditorSelection.cursor(0)
else if (dir > 0 && line.to == doc.length) return EditorSelection.cursor(line.to)
let otherLine = doc.line(line.number + dir)
let otherLineNo = line.number + dir * (distance == null ? 1 : Math.ceil(distance / view.defaultLineHeight))
if (dir < 0 && otherLineNo < 1) return EditorSelection.cursor(0)
else if (dir > 0 && otherLineNo > doc.lines) return EditorSelection.cursor(line.to)
let otherLine = doc.line(otherLineNo)
let result = otherLine.from
let seen = 0
for (const iter = doc.iterRange(otherLine.from, otherLine.to); seen >= goalCol && !iter.next().done;) {
Expand Down

0 comments on commit 7542a04

Please sign in to comment.