2025-08-07 17:41:10 +01:00
|
|
|
structure NormalMove =
|
|
|
|
|
struct
|
2025-08-07 17:57:47 +01:00
|
|
|
open AppType
|
|
|
|
|
|
2025-09-12 13:47:14 +01:00
|
|
|
fun moveToStart (app: app_type) : AppType.app_type =
|
2025-08-07 17:57:47 +01:00
|
|
|
let
|
2025-08-20 12:51:31 +01:00
|
|
|
val
|
|
|
|
|
{ buffer
|
|
|
|
|
, windowWidth
|
|
|
|
|
, windowHeight
|
|
|
|
|
, searchList
|
|
|
|
|
, searchString
|
|
|
|
|
, bufferModifyTime
|
2025-09-12 13:23:46 +01:00
|
|
|
, visualScrollColumn
|
2025-08-20 12:51:31 +01:00
|
|
|
, ...
|
|
|
|
|
} = app
|
2025-08-07 17:57:47 +01:00
|
|
|
|
|
|
|
|
val cursorIdx = 0
|
|
|
|
|
val startLine = 0
|
2025-09-12 13:23:46 +01:00
|
|
|
val buffer = LineGap.goToStart buffer
|
2025-08-07 17:57:47 +01:00
|
|
|
|
2025-09-12 13:23:46 +01:00
|
|
|
val drawMsg = NormalModeTextBuilder.build
|
2025-08-07 17:57:47 +01:00
|
|
|
( startLine
|
|
|
|
|
, cursorIdx
|
|
|
|
|
, buffer
|
|
|
|
|
, windowWidth
|
|
|
|
|
, windowHeight
|
|
|
|
|
, searchList
|
|
|
|
|
, searchString
|
2025-09-12 13:23:46 +01:00
|
|
|
, visualScrollColumn
|
2025-08-07 17:57:47 +01:00
|
|
|
)
|
2025-09-12 13:23:46 +01:00
|
|
|
val drawMsg = Vector.concat drawMsg
|
2025-09-12 13:47:14 +01:00
|
|
|
val drawMsg = DrawMsg.DRAW_TEXT drawMsg
|
|
|
|
|
val drawMsg = [MailboxType.DRAW drawMsg]
|
2025-08-07 17:57:47 +01:00
|
|
|
|
|
|
|
|
val mode = NORMAL_MODE ""
|
|
|
|
|
in
|
2025-08-31 06:28:05 +01:00
|
|
|
NormalModeWith.bufferAndCursorIdx
|
2025-08-20 12:51:31 +01:00
|
|
|
( app
|
|
|
|
|
, buffer
|
|
|
|
|
, cursorIdx
|
|
|
|
|
, mode
|
|
|
|
|
, startLine
|
|
|
|
|
, searchList
|
|
|
|
|
, drawMsg
|
|
|
|
|
, bufferModifyTime
|
2025-09-11 23:43:09 +01:00
|
|
|
, 0
|
2025-08-20 12:51:31 +01:00
|
|
|
)
|
2025-08-07 17:57:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun moveToEnd (app: app_type) =
|
|
|
|
|
let
|
2025-08-20 12:51:31 +01:00
|
|
|
val
|
|
|
|
|
{ buffer
|
|
|
|
|
, windowWidth
|
|
|
|
|
, windowHeight
|
|
|
|
|
, searchList
|
|
|
|
|
, searchString
|
|
|
|
|
, bufferModifyTime
|
2025-09-13 01:43:31 +01:00
|
|
|
, visualScrollColumn = prevScrollColumn
|
2025-09-13 18:15:30 +01:00
|
|
|
, startLine = prevLineNumber
|
2025-08-20 12:51:31 +01:00
|
|
|
, ...
|
|
|
|
|
} = app
|
2025-08-07 17:57:47 +01:00
|
|
|
|
|
|
|
|
val buffer = LineGap.goToEnd buffer
|
2025-09-16 07:52:47 +01:00
|
|
|
val {line = bufferLine, textLength, ...} = buffer
|
2025-08-07 17:57:47 +01:00
|
|
|
|
2025-09-16 07:52:47 +01:00
|
|
|
val bufferIdx = Int.max (0, textLength - 2)
|
2025-08-07 17:57:47 +01:00
|
|
|
val bufferLine = bufferLine - 1
|
|
|
|
|
|
|
|
|
|
val buffer = LineGap.goToIdx (bufferIdx, buffer)
|
2025-09-11 23:43:09 +01:00
|
|
|
val visualScrollColumn =
|
2025-09-13 05:12:17 +01:00
|
|
|
TextScroll.getScrollColumn
|
|
|
|
|
(buffer, bufferIdx, windowWidth, prevScrollColumn)
|
2025-08-07 17:57:47 +01:00
|
|
|
|
2025-09-13 18:15:30 +01:00
|
|
|
val bufferLine =
|
|
|
|
|
TextScroll.getStartLine (prevLineNumber, bufferLine, windowHeight)
|
2025-08-07 17:57:47 +01:00
|
|
|
val buffer = LineGap.goToLine (bufferLine, buffer)
|
|
|
|
|
|
2025-09-12 13:23:46 +01:00
|
|
|
val drawMsg = NormalModeTextBuilder.build
|
2025-08-07 17:57:47 +01:00
|
|
|
( bufferLine
|
2025-09-12 23:21:53 +01:00
|
|
|
, bufferIdx
|
2025-08-07 17:57:47 +01:00
|
|
|
, buffer
|
|
|
|
|
, windowWidth
|
|
|
|
|
, windowHeight
|
|
|
|
|
, searchList
|
|
|
|
|
, searchString
|
2025-09-12 13:23:46 +01:00
|
|
|
, visualScrollColumn
|
2025-08-07 17:57:47 +01:00
|
|
|
)
|
2025-09-12 13:23:46 +01:00
|
|
|
val drawMsg = Vector.concat drawMsg
|
2025-09-12 13:47:14 +01:00
|
|
|
val drawMsg = DrawMsg.DRAW_TEXT drawMsg
|
|
|
|
|
val drawMsg = [MailboxType.DRAW drawMsg]
|
2025-08-07 17:57:47 +01:00
|
|
|
|
|
|
|
|
val mode = NORMAL_MODE ""
|
|
|
|
|
in
|
2025-08-31 06:28:05 +01:00
|
|
|
NormalModeWith.bufferAndCursorIdx
|
2025-08-20 12:51:31 +01:00
|
|
|
( app
|
|
|
|
|
, buffer
|
|
|
|
|
, bufferIdx
|
|
|
|
|
, mode
|
|
|
|
|
, bufferLine
|
|
|
|
|
, searchList
|
|
|
|
|
, drawMsg
|
|
|
|
|
, bufferModifyTime
|
2025-09-11 23:43:09 +01:00
|
|
|
, visualScrollColumn
|
2025-08-20 12:51:31 +01:00
|
|
|
)
|
2025-08-07 17:57:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun moveToLine (app: app_type, reqLine) =
|
2025-09-16 22:09:15 +01:00
|
|
|
let
|
|
|
|
|
val reqLine = reqLine - 1
|
|
|
|
|
in
|
|
|
|
|
if reqLine = 0 then
|
|
|
|
|
moveToStart app
|
|
|
|
|
else
|
|
|
|
|
let
|
|
|
|
|
val
|
|
|
|
|
{ windowWidth
|
|
|
|
|
, windowHeight
|
|
|
|
|
, buffer
|
|
|
|
|
, startLine = prevLineNumber
|
|
|
|
|
, searchList
|
|
|
|
|
, searchString
|
|
|
|
|
, bufferModifyTime
|
|
|
|
|
, visualScrollColumn = prevScrollColumn
|
|
|
|
|
, ...
|
|
|
|
|
} = app
|
|
|
|
|
val buffer = LineGap.goToLine (reqLine, buffer)
|
|
|
|
|
|
|
|
|
|
(* get idx of first chr after linebreak *)
|
|
|
|
|
val cursorIdx = Cursor.getLineStartIdx (buffer, reqLine)
|
|
|
|
|
|
|
|
|
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
|
|
|
|
val visualScrollColumn =
|
|
|
|
|
TextScroll.getScrollColumn
|
|
|
|
|
(buffer, cursorIdx, windowWidth, prevScrollColumn)
|
|
|
|
|
|
2025-09-16 22:20:55 +01:00
|
|
|
val cursorLine = LineGap.idxToLineNumber (cursorIdx, buffer)
|
2025-09-16 22:09:15 +01:00
|
|
|
val startLine =
|
|
|
|
|
TextScroll.getStartLine (prevLineNumber, cursorLine, windowHeight)
|
|
|
|
|
|
|
|
|
|
val buffer = LineGap.goToLine (startLine, buffer)
|
|
|
|
|
|
|
|
|
|
val drawMsg = NormalModeTextBuilder.build
|
|
|
|
|
( startLine
|
|
|
|
|
, cursorIdx
|
|
|
|
|
, buffer
|
|
|
|
|
, windowWidth
|
|
|
|
|
, windowHeight
|
|
|
|
|
, searchList
|
|
|
|
|
, searchString
|
|
|
|
|
, visualScrollColumn
|
|
|
|
|
)
|
|
|
|
|
val drawMsg = Vector.concat drawMsg
|
|
|
|
|
val drawMsg = DrawMsg.DRAW_TEXT drawMsg
|
|
|
|
|
val drawMsg = [MailboxType.DRAW drawMsg]
|
|
|
|
|
|
|
|
|
|
val mode = NORMAL_MODE ""
|
|
|
|
|
in
|
|
|
|
|
NormalModeWith.bufferAndCursorIdx
|
|
|
|
|
( app
|
|
|
|
|
, buffer
|
|
|
|
|
, cursorIdx
|
|
|
|
|
, mode
|
|
|
|
|
, startLine
|
|
|
|
|
, searchList
|
|
|
|
|
, drawMsg
|
|
|
|
|
, bufferModifyTime
|
|
|
|
|
, visualScrollColumn
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
2025-08-07 17:57:47 +01:00
|
|
|
|
|
|
|
|
fun moveToMatchingPair (app: app_type) =
|
|
|
|
|
let
|
|
|
|
|
val
|
|
|
|
|
{ buffer
|
|
|
|
|
, cursorIdx
|
|
|
|
|
, windowWidth
|
|
|
|
|
, windowHeight
|
2025-09-13 05:12:17 +01:00
|
|
|
, startLine = prevLineNumber
|
2025-08-07 17:57:47 +01:00
|
|
|
, searchList
|
|
|
|
|
, searchString
|
2025-08-20 12:50:39 +01:00
|
|
|
, bufferModifyTime
|
2025-09-13 01:43:31 +01:00
|
|
|
, visualScrollColumn = prevScrollColumn
|
2025-08-07 17:57:47 +01:00
|
|
|
, ...
|
|
|
|
|
} = app
|
|
|
|
|
|
|
|
|
|
(* move LineGap and buffer to start of line *)
|
|
|
|
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
|
|
|
|
val cursorIdx = Cursor.matchPair (buffer, cursorIdx)
|
|
|
|
|
in
|
2025-09-11 23:43:09 +01:00
|
|
|
let
|
|
|
|
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
|
|
|
|
val visualScrollColumn =
|
2025-09-13 05:12:17 +01:00
|
|
|
TextScroll.getScrollColumn
|
|
|
|
|
(buffer, cursorIdx, windowWidth, prevScrollColumn)
|
|
|
|
|
|
2025-09-16 22:20:55 +01:00
|
|
|
val cursorLine = LineGap.idxToLineNumber (cursorIdx, buffer)
|
2025-09-13 05:12:17 +01:00
|
|
|
val startLine =
|
|
|
|
|
TextScroll.getStartLine (prevLineNumber, cursorLine, windowHeight)
|
2025-09-11 23:43:09 +01:00
|
|
|
|
|
|
|
|
val buffer = LineGap.goToLine (startLine, buffer)
|
|
|
|
|
|
2025-09-12 13:23:46 +01:00
|
|
|
val drawMsg = NormalModeTextBuilder.build
|
2025-09-11 23:43:09 +01:00
|
|
|
( startLine
|
|
|
|
|
, cursorIdx
|
|
|
|
|
, buffer
|
|
|
|
|
, windowWidth
|
|
|
|
|
, windowHeight
|
|
|
|
|
, searchList
|
|
|
|
|
, searchString
|
2025-09-12 13:23:46 +01:00
|
|
|
, visualScrollColumn
|
2025-09-11 23:43:09 +01:00
|
|
|
)
|
2025-09-12 13:23:46 +01:00
|
|
|
val drawMsg = Vector.concat drawMsg
|
2025-09-12 13:47:14 +01:00
|
|
|
val drawMsg = DrawMsg.DRAW_TEXT drawMsg
|
|
|
|
|
val drawMsg = [MailboxType.DRAW drawMsg]
|
2025-09-11 23:43:09 +01:00
|
|
|
in
|
|
|
|
|
NormalModeWith.bufferAndCursorIdx
|
|
|
|
|
( app
|
|
|
|
|
, buffer
|
|
|
|
|
, cursorIdx
|
|
|
|
|
, NORMAL_MODE ""
|
|
|
|
|
, startLine
|
|
|
|
|
, searchList
|
|
|
|
|
, drawMsg
|
|
|
|
|
, bufferModifyTime
|
|
|
|
|
, visualScrollColumn
|
|
|
|
|
)
|
|
|
|
|
end
|
2025-08-07 17:57:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun firstNonSpaceChr (app: app_type) =
|
|
|
|
|
let
|
2025-08-20 12:51:31 +01:00
|
|
|
val
|
|
|
|
|
{ buffer
|
|
|
|
|
, cursorIdx
|
|
|
|
|
, windowWidth
|
|
|
|
|
, windowHeight
|
|
|
|
|
, startLine
|
|
|
|
|
, searchList
|
|
|
|
|
, bufferModifyTime
|
|
|
|
|
, ...
|
|
|
|
|
} = app
|
2025-08-07 17:57:47 +01:00
|
|
|
|
|
|
|
|
(* move LineGap and buffer to start of line *)
|
|
|
|
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
|
|
|
|
val cursorIdx = Cursor.vi0 (buffer, cursorIdx)
|
|
|
|
|
|
|
|
|
|
(* move cursorIdx to first character on line *)
|
|
|
|
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
|
|
|
|
val cursorIdx = Cursor.firstNonSpaceChr (buffer, cursorIdx)
|
|
|
|
|
in
|
2025-08-31 06:28:05 +01:00
|
|
|
NormalFinish.buildTextAndClear
|
2025-08-20 12:51:31 +01:00
|
|
|
(app, buffer, cursorIdx, searchList, [], bufferModifyTime)
|
2025-08-07 17:57:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun helpMoveToChr (app: app_type, buffer, cursorIdx, count, fMove, chr) =
|
|
|
|
|
if count = 0 then
|
2025-09-13 05:12:17 +01:00
|
|
|
NormalFinish.buildTextAndClear
|
2025-08-20 12:50:39 +01:00
|
|
|
(app, buffer, cursorIdx, #searchList app, [], #bufferModifyTime app)
|
2025-08-07 17:57:47 +01:00
|
|
|
else
|
|
|
|
|
let
|
|
|
|
|
(* move LineGap to cursorIdx, which is necessary for finding newCursorIdx *)
|
|
|
|
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
|
|
|
|
val newCursorIdx = fMove (buffer, cursorIdx, chr)
|
|
|
|
|
val newCount = if cursorIdx = newCursorIdx then 0 else count - 1
|
|
|
|
|
in
|
|
|
|
|
helpMoveToChr (app, buffer, newCursorIdx, newCount, fMove, chr)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun moveToChr (app: app_type, count, fMove, chr) =
|
|
|
|
|
let val {cursorIdx, buffer, ...} = app
|
|
|
|
|
in helpMoveToChr (app, buffer, cursorIdx, count, fMove, chr)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun moveToNextMatch (app: app_type, count) =
|
|
|
|
|
let
|
2025-09-12 13:47:14 +01:00
|
|
|
val
|
|
|
|
|
{ cursorIdx
|
|
|
|
|
, searchList
|
|
|
|
|
, buffer
|
|
|
|
|
, bufferModifyTime
|
|
|
|
|
, visualScrollColumn
|
|
|
|
|
, ...
|
|
|
|
|
} = app
|
2025-08-07 17:57:47 +01:00
|
|
|
val newCursorIdx = SearchList.nextMatch (cursorIdx, searchList, count)
|
|
|
|
|
in
|
2025-08-07 18:09:52 +01:00
|
|
|
if newCursorIdx = ~1 then
|
2025-08-31 06:28:05 +01:00
|
|
|
NormalFinish.clearMode app
|
2025-08-07 18:09:52 +01:00
|
|
|
else
|
2025-09-13 05:12:17 +01:00
|
|
|
NormalFinish.buildTextAndClear
|
2025-08-20 12:50:39 +01:00
|
|
|
(app, buffer, newCursorIdx, searchList, [], bufferModifyTime)
|
2025-08-07 17:57:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun moveToPrevMatch (app: app_type, count) =
|
|
|
|
|
let
|
2025-08-20 12:50:39 +01:00
|
|
|
val {cursorIdx, searchList, buffer, bufferModifyTime, ...} = app
|
2025-08-07 17:57:47 +01:00
|
|
|
val newCursorIdx = SearchList.prevMatch (cursorIdx, searchList, count)
|
|
|
|
|
in
|
2025-08-07 18:09:52 +01:00
|
|
|
if newCursorIdx = ~1 then
|
2025-08-31 06:28:05 +01:00
|
|
|
NormalFinish.clearMode app
|
2025-08-07 18:09:52 +01:00
|
|
|
else
|
2025-09-13 05:12:17 +01:00
|
|
|
NormalFinish.buildTextAndClear
|
2025-08-20 12:50:39 +01:00
|
|
|
(app, buffer, newCursorIdx, searchList, [], bufferModifyTime)
|
2025-08-07 17:57:47 +01:00
|
|
|
end
|
2025-08-07 17:41:10 +01:00
|
|
|
end
|