2025-01-09 22:30:51 +00:00
|
|
|
signature MOVE =
|
|
|
|
|
sig
|
|
|
|
|
val fMove: LineGap.t * int -> int
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
signature MAKE_MOVE =
|
|
|
|
|
sig
|
|
|
|
|
val move: AppType.app_type * int -> AppType.app_type
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
functor MakeMove(Fn: MOVE): MAKE_MOVE =
|
|
|
|
|
struct
|
|
|
|
|
fun helpMove (app: AppType.app_type, buffer, cursorIdx, count) =
|
|
|
|
|
if count = 0 then
|
|
|
|
|
Finish.buildTextAndClear (app, buffer, cursorIdx, #searchList app)
|
|
|
|
|
else
|
|
|
|
|
(* move LineGap to cursorIdx, which is necessary for finding newCursorIdx *)
|
|
|
|
|
let
|
|
|
|
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
|
|
|
|
val newCursorIdx = Fn.fMove (buffer, cursorIdx)
|
|
|
|
|
val newCursorIdx = Cursor.clipIdx (buffer, newCursorIdx)
|
|
|
|
|
val newCount =
|
|
|
|
|
(* it's possible to loop a very high number like 5432131
|
|
|
|
|
* which will take a long time because of the high number of loops
|
|
|
|
|
* regardless of the data structure used.
|
|
|
|
|
* If this happens, and the newCursorIdx is the same as the old one,
|
|
|
|
|
* then skip to end of loop by going to base case. *)
|
|
|
|
|
if cursorIdx = newCursorIdx then 0
|
|
|
|
|
else count - 1
|
|
|
|
|
in
|
|
|
|
|
helpMove (app, buffer, newCursorIdx, newCount)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun move (app: AppType.app_type, count) =
|
|
|
|
|
let val {cursorIdx, buffer, ...} = app
|
|
|
|
|
in helpMove (app, buffer, cursorIdx, count)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
structure MoveViH = MakeMove (struct val fMove = Cursor.viH end)
|
|
|
|
|
structure MoveViJ = MakeMove (struct val fMove = Cursor.viJ end)
|
|
|
|
|
structure MoveViK = MakeMove (struct val fMove = Cursor.viK end)
|
|
|
|
|
structure MoveViL = MakeMove (struct val fMove = Cursor.viL end)
|
|
|
|
|
|
2025-08-03 14:17:25 +01:00
|
|
|
structure MoveToStartOfLine = MakeMove (struct val fMove = Cursor.vi0 end)
|
|
|
|
|
structure MoveToEndOfLine = MakeMove (struct val fMove = Cursor.viDlr end)
|
|
|
|
|
|
|
|
|
|
signature DFA_MOVE =
|
|
|
|
|
sig
|
|
|
|
|
val fMove: LineGap.t * int * int -> int
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
signature MAKE_DFA_MOVE =
|
|
|
|
|
sig
|
|
|
|
|
val move: AppType.app_type * int -> AppType.app_type
|
|
|
|
|
end
|
2025-01-09 22:30:51 +00:00
|
|
|
|
2025-08-03 14:17:25 +01:00
|
|
|
functor MakeDfaMove(Fn: DFA_MOVE): MAKE_DFA_MOVE =
|
|
|
|
|
struct
|
|
|
|
|
fun move (app: AppType.app_type, count) =
|
|
|
|
|
let
|
|
|
|
|
val {buffer, cursorIdx, ...} = app
|
|
|
|
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
|
|
|
|
val cursorIdx = Fn.fMove (buffer, cursorIdx, count)
|
|
|
|
|
in
|
|
|
|
|
Finish.buildTextAndClear (app, buffer, cursorIdx, #searchList app)
|
|
|
|
|
end
|
|
|
|
|
end
|
2025-01-09 22:30:51 +00:00
|
|
|
|
2025-08-03 14:17:25 +01:00
|
|
|
structure MoveToNextWord = MakeDfaMove (struct val fMove = Cursor.nextWord end)
|
|
|
|
|
structure MoveToNextWORD = MakeDfaMove (struct val fMove = Cursor.nextWORD end)
|
|
|
|
|
|
2025-08-03 14:18:17 +01:00
|
|
|
structure MoveToEndOfWord =
|
|
|
|
|
MakeDfaMove (struct val fMove = Cursor.endOfWord end)
|
|
|
|
|
structure MoveToEndOfWORD =
|
|
|
|
|
MakeDfaMove (struct val fMove = Cursor.endOfWORD end)
|
2025-08-03 14:17:25 +01:00
|
|
|
|
|
|
|
|
structure MoveToPrevWord = MakeDfaMove (struct val fMove = Cursor.prevWord end)
|
|
|
|
|
structure MoveToPrevWORD = MakeDfaMove (struct val fMove = Cursor.prevWORD end)
|
2025-01-09 22:30:51 +00:00
|
|
|
|
|
|
|
|
structure MoveToEndOfPrevWord =
|
2025-08-03 14:17:25 +01:00
|
|
|
MakeDfaMove (struct val fMove = Cursor.endOfPrevWord end)
|
2025-01-09 22:30:51 +00:00
|
|
|
structure MoveToEndOfPrevWORD =
|
2025-08-03 14:17:25 +01:00
|
|
|
MakeDfaMove (struct val fMove = Cursor.endOfPrevWORD end)
|