change line indexing in AppUpdate.moveToLine from 0-based to 1-based (so first line can be access with 1G, second with 2G, as is normal with Vim)

This commit is contained in:
2024-11-04 02:56:57 +00:00
parent 66d4346c74
commit a0a8fcc17b
2 changed files with 28 additions and 20 deletions

View File

@@ -69,8 +69,13 @@ struct
val bufferLine = bufferLine - 1 val bufferLine = bufferLine - 1
val buffer = LineGap.goToIdx (bufferIdx, buffer) val buffer = LineGap.goToIdx (bufferIdx, buffer)
val bufferLine = TextWindow.getStartLineWithCursorCentered val bufferLine =
(buffer, bufferIdx, bufferLine, windowWidth, windowHeight) let
val maxHeight = windowHeight - (TextConstants.ySpace * 2)
in
TextWindow.getStartLineWithCursorCentered
(buffer, bufferIdx, bufferLine, windowWidth, maxHeight)
end
val buffer = LineGap.goToLine (bufferLine, buffer) val buffer = LineGap.goToLine (bufferLine, buffer)
val drawMsg = val drawMsg =
@@ -85,28 +90,31 @@ struct
end end
fun moveToLine (app: app_type, reqLine) = fun moveToLine (app: app_type, reqLine) =
let if reqLine = 0 then
val {windowWidth, windowHeight, buffer, startLine = origLine, ...} = app moveToStart app
val buffer = LineGap.goToLine (reqLine, buffer) else
let
val {windowWidth, windowHeight, buffer, startLine = origLine, ...} = app
val buffer = LineGap.goToLine (reqLine, buffer)
(* get idx of first chr after linebreak *) (* get idx of first chr after linebreak *)
val cursorIdx = Cursor.getLineStartIdx (buffer, reqLine) val cursorIdx = Cursor.getLineStartIdx (buffer, reqLine)
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
val startLine = TextWindow.getStartLineWithCursorCentered val startLine = TextWindow.getStartLineWithCursorCentered
(buffer, cursorIdx, origLine, windowWidth, windowHeight div 2) (buffer, cursorIdx, origLine, windowWidth, windowHeight div 2)
val buffer = LineGap.goToLine (startLine, buffer) val buffer = LineGap.goToLine (startLine, buffer)
val newApp = AppWith.bufferAndCursorIdx val newApp = AppWith.bufferAndCursorIdx
(app, buffer, cursorIdx, NORMAL_MODE "", startLine) (app, buffer, cursorIdx, NORMAL_MODE "", startLine)
val drawMsg = val drawMsg =
TextBuilder.build TextBuilder.build
(startLine, cursorIdx, buffer, windowWidth, windowHeight) (startLine, cursorIdx, buffer, windowWidth, windowHeight)
in in
(newApp, drawMsg) (newApp, drawMsg)
end end
fun helpMove (app: app_type, buffer, cursorIdx, count, fMove) = fun helpMove (app: app_type, buffer, cursorIdx, count, fMove) =
if count = 0 then if count = 0 then
@@ -285,7 +293,7 @@ struct
if String.size str = 0 then if String.size str = 0 then
moveToEnd app moveToEnd app
else else
moveToLine (app, count) moveToLine (app, count - 1)
| #"%" => moveToMatchingPair app | #"%" => moveToMatchingPair app
(* multi-char commands which can be appended *) (* multi-char commands which can be appended *)
| #"t" => appendChr (app, chr, str) | #"t" => appendChr (app, chr, str)

BIN
shf

Binary file not shown.