Skip to content

Commit

Permalink
Improve behavior of moveVertically on line wrap boundaries
Browse files Browse the repository at this point in the history
FIX: Fix some issues with the way `moveVertically` behaved for positions on
line wrap points.

Closes codemirror/dev#1255
  • Loading branch information
marijnh committed Sep 18, 2023
1 parent b34a927 commit bdd2f10
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export function moveVertically(view: EditorView, start: SelectionRange, forward:
if (startPos == (forward ? view.state.doc.length : 0)) return EditorSelection.cursor(startPos, start.assoc)
let goal = start.goalColumn, startY
let rect = view.contentDOM.getBoundingClientRect()
let startCoords = view.coordsAtPos(startPos), docTop = view.documentTop
let startCoords = view.coordsAtPos(startPos, start.assoc || -1), docTop = view.documentTop
if (startCoords) {
if (goal == null) goal = startCoords.left - rect.left
startY = dir < 0 ? startCoords.top : startCoords.bottom
Expand All @@ -314,8 +314,11 @@ export function moveVertically(view: EditorView, start: SelectionRange, forward:
for (let extra = 0;; extra += 10) {
let curY = startY + (dist + extra) * dir
let pos = posAtCoords(view, {x: resolvedGoal, y: curY}, false, dir)!
if (curY < rect.top || curY > rect.bottom || (dir < 0 ? pos < startPos : pos > startPos))
return EditorSelection.cursor(pos, start.assoc, undefined, goal)
if (curY < rect.top || curY > rect.bottom || (dir < 0 ? pos < startPos : pos > startPos)) {
let charRect = view.docView.coordsForChar(pos)
let assoc = !charRect || curY < charRect.top ? -1 : 1
return EditorSelection.cursor(pos, assoc, undefined, goal)
}
}
}

Expand Down

0 comments on commit bdd2f10

Please sign in to comment.