when pressing fcore/text-window.sml to match pair, only recentre text window if matching pair is not currently visible on screen

This commit is contained in:
2024-11-02 12:34:23 +00:00
parent 33f2bf7b58
commit 2a8e02ff3a
3 changed files with 77 additions and 28 deletions

View File

@@ -131,23 +131,43 @@ struct
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val cursorIdx = Cursor.matchPair (buffer, cursorIdx)
val buffer = LineGap.goToIdx (cursorIdx, buffer)
(* todo:
* check if cursorIdx is visible on screen first,
* and only get new startLine if it is not visible *)
val startLine = TextWindow.getStartLineWithCursorCentered
(buffer, cursorIdx, startLine, windowWidth, windowHeight div 2)
val buffer = LineGap.goToLine (startLine, buffer)
val newApp = AppWith.bufferAndCursorIdx
(app, buffer, cursorIdx, NORMAL_MODE "", startLine)
val drawMsg =
TextBuilder.build
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
in
(newApp, drawMsg)
if TextWindow.isCursorVisible
(buffer, cursorIdx, startLine, windowWidth, windowHeight)
then
(* if visible, just need to redraw; no need to get line *)
let
val buffer = LineGap.goToLine (startLine, buffer)
val newApp = AppWith.bufferAndCursorIdx
(app, buffer, cursorIdx, NORMAL_MODE "", startLine)
val drawMsg =
TextBuilder.build
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
in
(newApp, drawMsg)
end
else
(* not visible, so need to get startLine where cursor is visible *)
let
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val startLine =
TextWindow.getStartLineWithCursorCentered
(buffer, cursorIdx, startLine, windowWidth, windowHeight div 2)
val buffer = LineGap.goToLine (startLine, buffer)
val newApp = AppWith.bufferAndCursorIdx
(app, buffer, cursorIdx, NORMAL_MODE "", startLine)
val drawMsg =
TextBuilder.build
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
in
(newApp, drawMsg)
end
end
fun firstNonSpaceChr (app: app_type) =