amend motion to move to a line: if the requested line has a linebreak as the next character after it, stay at the current position, or else add 1 to the linebreak's idx so that we go to the first character of the line

This commit is contained in:
2025-09-19 04:03:54 +01:00
parent d871ac451f
commit b6244d4962
2 changed files with 11 additions and 2 deletions

View File

@@ -129,8 +129,17 @@ struct
(* get idx of first chr after linebreak *)
val cursorIdx = Cursor.getLineStartIdx (buffer, reqLine)
val buffer = LineGap.goToIdx (cursorIdx, buffer)
(* we got the line start idx, but we want to move to the index
* after it, where the first character of the line is.
* Unless the next character is a line break,
* in which case we want to stay at the current idx. *)
val cursorIdx =
if Cursor.isNextChrEndOfLine (buffer, cursorIdx) then cursorIdx
else cursorIdx + 1
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val visualScrollColumn =
TextScroll.getScrollColumn
(buffer, cursorIdx, windowWidth, prevScrollColumn)