pass time parameter in normal-delete.sml

This commit is contained in:
2025-08-20 13:00:36 +01:00
parent c4f3e921a3
commit f97a2944ae
2 changed files with 61 additions and 53 deletions

View File

@@ -3,7 +3,7 @@ struct
open AppType open AppType
open MailboxType open MailboxType
fun deleteAndFinish (app: app_type, low, length, buffer) = fun deleteAndFinish (app: app_type, low, length, buffer, time) =
let let
val buffer = LineGap.delete (low, length, buffer) val buffer = LineGap.delete (low, length, buffer)
@@ -16,11 +16,11 @@ struct
val buffer = LineGap.goToIdx (low, buffer) val buffer = LineGap.goToIdx (low, buffer)
in in
Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg) Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg, time)
end end
(* equivalent of vi's 'x' command **) (* equivalent of vi's 'x' command **)
fun helpRemoveChr (app: app_type, buffer, cursorIdx, count) = fun helpRemoveChr (app: app_type, buffer, cursorIdx, count, time) =
if count = 0 then if count = 0 then
let let
val searchString = #searchString app val searchString = #searchString app
@@ -32,7 +32,7 @@ struct
SearchList.buildRange (buffer, searchString, cursorIdx - 777) SearchList.buildRange (buffer, searchString, cursorIdx - 777)
in in
Finish.buildTextAndClear Finish.buildTextAndClear
(app, buffer, cursorIdx, searchList, initialMsg) (app, buffer, cursorIdx, searchList, initialMsg, time)
end end
else else
let let
@@ -56,9 +56,9 @@ struct
(* vi simply doesn't do anything on 'x' command (* vi simply doesn't do anything on 'x' command
* when cursor is at start of line, and next chr is line break * when cursor is at start of line, and next chr is line break
* so skip to end of loop by passing count of 0 *) * so skip to end of loop by passing count of 0 *)
helpRemoveChr (app, buffer, cursorIdx, 0) helpRemoveChr (app, buffer, cursorIdx, 0, time)
else if cursorIsStart then else if cursorIsStart then
helpRemoveChr (app, buffer, cursorIdx, 0) helpRemoveChr (app, buffer, cursorIdx, 0, time)
else if nextIsEnd then else if nextIsEnd then
let let
(* delete char at cursor and then decrement cursorIdx by 1 (* delete char at cursor and then decrement cursorIdx by 1
@@ -73,21 +73,22 @@ struct
then cursorIdx then cursorIdx
else cursorIdx - 1 else cursorIdx - 1
in in
helpRemoveChr (app, buffer, cursorIdx, count - 1) helpRemoveChr (app, buffer, cursorIdx, count - 1, time)
end end
else else
let let
val searchString = #searchString app val searchString = #searchString app
val buffer = LineGap.delete (cursorIdx, 1, buffer) val buffer = LineGap.delete (cursorIdx, 1, buffer)
in in
helpRemoveChr (app, buffer, cursorIdx, count - 1) helpRemoveChr (app, buffer, cursorIdx, count - 1, time)
end end
end end
fun removeChr (app: app_type, count) = fun removeChr (app: app_type, count, time) =
helpRemoveChr (app, #buffer app, #cursorIdx app, count) helpRemoveChr (app, #buffer app, #cursorIdx app, count, time)
fun helpDelete (app: app_type, buffer, cursorIdx, otherIdx, count, fMove) = fun helpDelete
(app: app_type, buffer, cursorIdx, otherIdx, count, fMove, time) =
(* As a small optimisation to reduce allocations, (* As a small optimisation to reduce allocations,
* we accumulate otherIdx by calling fMove with it and the buffer * we accumulate otherIdx by calling fMove with it and the buffer
* on each loop. * on each loop.
@@ -119,7 +120,7 @@ struct
val cursorIdx = Cursor.clipIdx (buffer, low) val cursorIdx = Cursor.clipIdx (buffer, low)
in in
Finish.buildTextAndClear Finish.buildTextAndClear
(app, buffer, cursorIdx, searchList, initialMsg) (app, buffer, cursorIdx, searchList, initialMsg, time)
end end
else else
let let
@@ -128,13 +129,15 @@ struct
val newOtherIdx = fMove (buffer, otherIdx) val newOtherIdx = fMove (buffer, otherIdx)
val newCount = if newOtherIdx = otherIdx then 0 else count - 1 val newCount = if newOtherIdx = otherIdx then 0 else count - 1
in in
helpDelete (app, buffer, cursorIdx, newOtherIdx, newCount, fMove) helpDelete (app, buffer, cursorIdx, newOtherIdx, newCount, fMove, time)
end end
fun delete (app: app_type, count, fMove) = fun delete (app: app_type, count, fMove, time) =
helpDelete (app, #buffer app, #cursorIdx app, #cursorIdx app, count, fMove) let val {buffer, cursorIdx, ...} = app
in helpDelete (app, buffer, cursorIdx, cursorIdx, count, fMove, time)
end
fun deleteByDfa (app: app_type, count, fMove) = fun deleteByDfa (app: app_type, count, fMove, time) =
let let
val {buffer, cursorIdx, searchString, ...} = app val {buffer, cursorIdx, searchString, ...} = app
@@ -145,10 +148,10 @@ struct
val high = Int.max (cursorIdx, otherIdx) val high = Int.max (cursorIdx, otherIdx)
val length = high - low val length = high - low
in in
deleteAndFinish (app, low, length, buffer) deleteAndFinish (app, low, length, buffer, time)
end end
fun deleteToEndOfLine (app: app_type) = fun deleteToEndOfLine (app: app_type, time) =
let let
val {buffer, cursorIdx, ...} = app val {buffer, cursorIdx, ...} = app
in in
@@ -168,11 +171,11 @@ struct
val length = lastChr - cursorIdx val length = lastChr - cursorIdx
val buffer = LineGap.delete (cursorIdx, length, buffer) val buffer = LineGap.delete (cursorIdx, length, buffer)
in in
helpRemoveChr (app, buffer, cursorIdx, 1) helpRemoveChr (app, buffer, cursorIdx, 1, time)
end end
end end
fun deleteLine (app: app_type, count) = fun deleteLine (app: app_type, count, time) =
let let
val {buffer, cursorIdx, searchString, ...} = app val {buffer, cursorIdx, searchString, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
@@ -182,16 +185,16 @@ struct
val length = finishIdx - startIdx val length = finishIdx - startIdx
in in
deleteAndFinish (app, startIdx, length, buffer) deleteAndFinish (app, startIdx, length, buffer, time)
end end
fun helpDeleteLineBack (app, buffer, low, high, count) = fun helpDeleteLineBack (app, buffer, low, high, count, time) =
if count = 0 then if count = 0 then
let let
val low = Int.max (low, 0) val low = Int.max (low, 0)
val length = high - low val length = high - low
in in
deleteAndFinish (app, low, length, buffer) deleteAndFinish (app, low, length, buffer, time)
end end
else else
let let
@@ -201,19 +204,19 @@ struct
val low = Cursor.vi0 (buffer, low) val low = Cursor.vi0 (buffer, low)
val newCount = if low = 0 then 0 else count - 1 val newCount = if low = 0 then 0 else count - 1
in in
helpDeleteLineBack (app, buffer, low, high, newCount) helpDeleteLineBack (app, buffer, low, high, newCount, time)
end end
fun deleteLineBack (app: app_type, count) = fun deleteLineBack (app: app_type, count, time) =
let let
val {buffer, cursorIdx, ...} = app val {buffer, cursorIdx, ...} = app
val low = Cursor.vi0 (buffer, cursorIdx) val low = Cursor.vi0 (buffer, cursorIdx)
val high = Cursor.viDlr (buffer, cursorIdx, 1) + 1 val high = Cursor.viDlr (buffer, cursorIdx, 1) + 1
in in
helpDeleteLineBack (app, buffer, low, high, count) helpDeleteLineBack (app, buffer, low, high, count, time)
end end
fun deleteToFirstNonSpaceChr (app: app_type) = fun deleteToFirstNonSpaceChr (app: app_type, time) =
let let
val val
{ buffer { buffer
@@ -237,7 +240,7 @@ struct
val high = Int.max (cursorIdx, otherIdx) val high = Int.max (cursorIdx, otherIdx)
val length = high - low val length = high - low
in in
deleteAndFinish (app, low, length, buffer) deleteAndFinish (app, low, length, buffer, time)
end end
fun helpDeleteToChr fun helpDeleteToChr
@@ -248,7 +251,7 @@ struct
val high = Int.max (cursorIdx, otherIdx) val high = Int.max (cursorIdx, otherIdx)
val length = high - low val length = high - low
in in
deleteAndFinish (app, low, length, buffer) deleteAndFinish (app, low, length, buffer, #bufferModifyTime app)
end end
else else
let let
@@ -273,7 +276,7 @@ struct
, chr , chr
) )
fun deleteToStart (app: app_type) = fun deleteToStart (app: app_type, time) =
let let
val {cursorIdx, buffer, windowWidth, windowHeight, searchString, ...} = val {cursorIdx, buffer, windowWidth, windowHeight, searchString, ...} =
app app
@@ -305,10 +308,10 @@ struct
val mode = NORMAL_MODE "" val mode = NORMAL_MODE ""
in in
AppWith.bufferAndCursorIdx AppWith.bufferAndCursorIdx
(app, buffer, cursorIdx, mode, startLine, searchList, drawMsg) (app, buffer, cursorIdx, mode, startLine, searchList, drawMsg, time)
end end
fun helpDeleteToMatch (app: app_type, low, high) = fun helpDeleteToMatch (app: app_type, low, high, time) =
let let
val {buffer, searchString, ...} = app val {buffer, searchString, ...} = app
val length = high - low val length = high - low
@@ -322,10 +325,10 @@ struct
val buffer = LineGap.goToIdx (low, buffer) val buffer = LineGap.goToIdx (low, buffer)
in in
Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg) Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg, time)
end end
fun deleteToNextMatch (app: app_type, count) = fun deleteToNextMatch (app: app_type, count, time) =
let let
val {cursorIdx, searchList, ...} = app val {cursorIdx, searchList, ...} = app
val newCursorIdx = SearchList.nextMatch (cursorIdx, searchList, count) val newCursorIdx = SearchList.nextMatch (cursorIdx, searchList, count)
@@ -333,10 +336,10 @@ struct
if newCursorIdx = ~1 orelse newCursorIdx <= cursorIdx then if newCursorIdx = ~1 orelse newCursorIdx <= cursorIdx then
Finish.clearMode app Finish.clearMode app
else else
helpDeleteToMatch (app, cursorIdx, newCursorIdx) helpDeleteToMatch (app, cursorIdx, newCursorIdx, time)
end end
fun deleteToPrevMatch (app: app_type, count) = fun deleteToPrevMatch (app: app_type, count, time) =
let let
val {cursorIdx, searchList, ...} = app val {cursorIdx, searchList, ...} = app
val newCursorIdx = SearchList.prevMatch (cursorIdx, searchList, count) val newCursorIdx = SearchList.prevMatch (cursorIdx, searchList, count)
@@ -344,10 +347,10 @@ struct
if newCursorIdx = ~1 orelse newCursorIdx >= cursorIdx then if newCursorIdx = ~1 orelse newCursorIdx >= cursorIdx then
Finish.clearMode app Finish.clearMode app
else else
helpDeleteToMatch (app, newCursorIdx, cursorIdx) helpDeleteToMatch (app, newCursorIdx, cursorIdx, time)
end end
fun deleteInsideWord (app: app_type) = fun deleteInsideWord (app: app_type, time) =
let let
val {buffer, cursorIdx, searchString, ...} = app val {buffer, cursorIdx, searchString, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
@@ -370,11 +373,12 @@ struct
val buffer = LineGap.goToIdx (low, buffer) val buffer = LineGap.goToIdx (low, buffer)
in in
Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg) Finish.buildTextAndClear
(app, buffer, low, searchList, initialMsg, time)
end end
end end
fun deleteInsideWORD (app: app_type) = fun deleteInsideWORD (app: app_type, time) =
let let
val {buffer, cursorIdx, searchString, ...} = app val {buffer, cursorIdx, searchString, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
@@ -397,11 +401,12 @@ struct
val buffer = LineGap.goToIdx (low, buffer) val buffer = LineGap.goToIdx (low, buffer)
in in
Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg) Finish.buildTextAndClear
(app, buffer, low, searchList, initialMsg, time)
end end
end end
fun finishAfterDeleteInside (app: app_type, origLow, high) = fun finishAfterDeleteInside (app: app_type, origLow, high, time) =
if origLow = high then if origLow = high then
Finish.clearMode app Finish.clearMode app
else else
@@ -419,10 +424,11 @@ struct
val buffer = LineGap.goToIdx (origLow, buffer) val buffer = LineGap.goToIdx (origLow, buffer)
in in
Finish.buildTextAndClear (app, buffer, origLow, searchList, initialMsg) Finish.buildTextAndClear
(app, buffer, origLow, searchList, initialMsg, time)
end end
fun deleteInsideChrOpen (app: app_type, chr) = fun deleteInsideChrOpen (app: app_type, chr, time) =
let let
val {cursorIdx, buffer, ...} = app val {cursorIdx, buffer, ...} = app
@@ -433,10 +439,10 @@ struct
val buffer = LineGap.goToIdx (origLow, buffer) val buffer = LineGap.goToIdx (origLow, buffer)
val high = Cursor.matchPair (buffer, origLow) val high = Cursor.matchPair (buffer, origLow)
in in
finishAfterDeleteInside (app, origLow, high) finishAfterDeleteInside (app, origLow, high, time)
end end
fun deleteInsideChrClose (app: app_type, chr) = fun deleteInsideChrClose (app: app_type, chr, time) =
let let
val {cursorIdx, buffer, ...} = app val {cursorIdx, buffer, ...} = app
@@ -447,10 +453,10 @@ struct
val buffer = LineGap.goToIdx (high, buffer) val buffer = LineGap.goToIdx (high, buffer)
val origLow = Cursor.matchPair (buffer, high) val origLow = Cursor.matchPair (buffer, high)
in in
finishAfterDeleteInside (app, origLow, high) finishAfterDeleteInside (app, origLow, high, time)
end end
fun deleteAroundChrOpen (app: app_type, chr) = fun deleteAroundChrOpen (app: app_type, chr, time) =
let let
val {cursorIdx, buffer, ...} = app val {cursorIdx, buffer, ...} = app
@@ -462,10 +468,10 @@ struct
val high = Cursor.matchPair (buffer, low) val high = Cursor.matchPair (buffer, low)
in in
if low = high then Finish.clearMode app if low = high then Finish.clearMode app
else deleteAndFinish (app, low, high - low + 1, buffer) else deleteAndFinish (app, low, high - low + 1, buffer, time)
end end
fun deleteAroundChrClose (app: app_type, chr) = fun deleteAroundChrClose (app: app_type, chr, time) =
let let
val {cursorIdx, buffer, ...} = app val {cursorIdx, buffer, ...} = app
@@ -477,10 +483,10 @@ struct
val low = Cursor.matchPair (buffer, high) val low = Cursor.matchPair (buffer, high)
in in
if low = high then Finish.clearMode app if low = high then Finish.clearMode app
else deleteAndFinish (app, low, high - low + 1, buffer) else deleteAndFinish (app, low, high - low + 1, buffer, time)
end end
fun deletePair (app: app_type) = fun deletePair (app: app_type, time) =
let let
val {cursorIdx, buffer, ...} = app val {cursorIdx, buffer, ...} = app
val otherIdx = Cursor.matchPair (buffer, cursorIdx) val otherIdx = Cursor.matchPair (buffer, cursorIdx)
@@ -514,7 +520,8 @@ struct
val buffer = LineGap.goToIdx (low, buffer) val buffer = LineGap.goToIdx (low, buffer)
in in
Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg) Finish.buildTextAndClear
(app, buffer, low, searchList, initialMsg, time)
end end
end end
end end

View File

@@ -34,3 +34,4 @@ fcore/finish.sml
fcore/move.sml fcore/move.sml
fcore/normal-mode/normal-move.sml fcore/normal-mode/normal-move.sml
fcore/normal-mode/normal-delete.sml