break out of loop early in 'helpMove' and 'helpMoveToChr' functions, in case where calling 'fMove' returned the same value as before
This commit is contained in:
@@ -189,10 +189,19 @@ struct
|
|||||||
(* 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 cursorIdx = fMove (buffer, cursorIdx)
|
val newCursorIdx = fMove (buffer, cursorIdx)
|
||||||
val cursorIdx = Cursor.clipIdx (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, cursorIdx, count - 1, fMove)
|
helpMove (app, buffer, newCursorIdx, newCount, fMove)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun move (app: app_type, count, fMove) =
|
fun move (app: app_type, count, fMove) =
|
||||||
@@ -267,9 +276,13 @@ struct
|
|||||||
let
|
let
|
||||||
(* move LineGap to cursorIdx, which is necessary for finding newCursorIdx *)
|
(* move LineGap to cursorIdx, which is necessary for finding newCursorIdx *)
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
val cursorIdx = fMove (buffer, cursorIdx, chr)
|
val newCursorIdx = fMove (buffer, cursorIdx, chr)
|
||||||
|
val newCount =
|
||||||
|
if cursorIdx = newCursorIdx
|
||||||
|
then 0
|
||||||
|
else cursorIdx - 1
|
||||||
in
|
in
|
||||||
helpMoveToChr (app, buffer, cursorIdx, count - 1, fMove, chr)
|
helpMoveToChr (app, buffer, newCursorIdx, newCount, fMove, chr)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun moveToChr (app: app_type, count, fMove, chr) =
|
fun moveToChr (app: app_type, count, fMove, chr) =
|
||||||
|
|||||||
Reference in New Issue
Block a user