rewrite 'MakeMove' functor in fcore/move.sml to use textLength field instead of Cursor.clipIdx function
This commit is contained in:
@@ -10,30 +10,30 @@ end
|
|||||||
|
|
||||||
functor MakeMove(Fn: MOVE): MAKE_MOVE =
|
functor MakeMove(Fn: MOVE): MAKE_MOVE =
|
||||||
struct
|
struct
|
||||||
|
fun finish (app: AppType.app_type, buffer, cursorIdx) =
|
||||||
|
let
|
||||||
|
val {searchList, bufferModifyTime, ...} = app
|
||||||
|
in
|
||||||
|
NormalFinish.buildTextAndClear
|
||||||
|
(app, buffer, cursorIdx, searchList, [], bufferModifyTime)
|
||||||
|
end
|
||||||
|
|
||||||
fun helpMove (app: AppType.app_type, buffer, cursorIdx, count) =
|
fun helpMove (app: AppType.app_type, buffer, cursorIdx, count) =
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
let
|
finish (app, buffer, cursorIdx)
|
||||||
val {searchList, bufferModifyTime, ...} = app
|
|
||||||
in
|
|
||||||
NormalFinish.buildTextAndClear
|
|
||||||
(app, buffer, cursorIdx, searchList, [], bufferModifyTime)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
(* move LineGap to cursorIdx, which is necessary for finding newCursorIdx *)
|
(* move LineGap to cursorIdx, which is necessary for finding newCursorIdx *)
|
||||||
let
|
let
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
|
val textLength = #textLength buffer
|
||||||
val newCursorIdx = Fn.fMove (buffer, cursorIdx)
|
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
|
in
|
||||||
helpMove (app, buffer, newCursorIdx, newCount)
|
if newCursorIdx >= textLength - 2 then
|
||||||
|
let val newCursorIdx = Int.max (textLength - 2, 0)
|
||||||
|
in finish (app, buffer, newCursorIdx)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
helpMove (app, buffer, newCursorIdx, count - 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun move (app: AppType.app_type, count) =
|
fun move (app: AppType.app_type, count) =
|
||||||
|
|||||||
Reference in New Issue
Block a user