fix minor bug when deleting around (with motion like da( or da< or da) or da>). The bug was that, if the last character we delete with the highest index is also the last character at the end of this line, we deleted the range properly but placed the cursor at a linebreak. In this case, the cursor is meant to be a single character before the line break, and after this commit, we have this desired behaviour.

This commit is contained in:
2025-09-06 02:46:49 +01:00
parent 0506cf6176
commit fb6cab7d0d

View File

@@ -3,10 +3,8 @@ struct
open AppType open AppType
open MailboxType open MailboxType
fun deleteAndFinish (app: app_type, low, length, buffer, time) = fun finishAfterDeletingBuffer (app: app_type, low, buffer, time) =
let let
val buffer = LineGap.delete (low, length, buffer)
val searchString = #searchString app val searchString = #searchString app
val buffer = LineGap.goToStart buffer val buffer = LineGap.goToStart buffer
val initialMsg = [SEARCH (buffer, searchString)] val initialMsg = [SEARCH (buffer, searchString)]
@@ -20,6 +18,11 @@ struct
(app, buffer, low, searchList, initialMsg, time) (app, buffer, low, searchList, initialMsg, time)
end end
fun deleteAndFinish (app: app_type, low, length, buffer, time) =
let val buffer = LineGap.delete (low, length, buffer)
in finishAfterDeletingBuffer (app, low, buffer, time)
end
(* equivalent of vi's 'x' command **) (* equivalent of vi's 'x' command **)
fun helpRemoveChr (app: app_type, buffer, cursorIdx, count, time) = fun helpRemoveChr (app: app_type, buffer, cursorIdx, count, time) =
if count = 0 then if count = 0 then
@@ -507,6 +510,18 @@ struct
finishAfterDeleteInside (app, origLow, high, time) finishAfterDeleteInside (app, origLow, high, time)
end end
fun finishDeleteAroundChr (app, low, high, buffer, time) =
let
val length = high - low + 1
val buffer = LineGap.delete (low, length, buffer)
val buffer = LineGap.goToIdx (low, buffer)
val low =
if Cursor.isCursorAtStartOfLine (buffer, low) then Int.max (low - 1, 0)
else low
in
finishAfterDeletingBuffer (app, low, buffer, time)
end
fun deleteAroundChrOpen (app: app_type, chr, time) = fun deleteAroundChrOpen (app: app_type, chr, time) =
let let
val {cursorIdx, buffer, ...} = app val {cursorIdx, buffer, ...} = app
@@ -519,7 +534,7 @@ struct
val high = Cursor.matchPair (buffer, low) val high = Cursor.matchPair (buffer, low)
in in
if low = high then NormalFinish.clearMode app if low = high then NormalFinish.clearMode app
else deleteAndFinish (app, low, high - low + 1, buffer, time) else finishDeleteAroundChr (app, low, high, buffer, time)
end end
fun deleteAroundChrClose (app: app_type, chr, time) = fun deleteAroundChrClose (app: app_type, chr, time) =
@@ -534,7 +549,7 @@ struct
val low = Cursor.matchPair (buffer, high) val low = Cursor.matchPair (buffer, high)
in in
if low = high then NormalFinish.clearMode app if low = high then NormalFinish.clearMode app
else deleteAndFinish (app, low, high - low + 1, buffer, time) else finishDeleteAroundChr (app, low, high, buffer, time)
end end
fun deletePair (app: app_type, time) = fun deletePair (app: app_type, time) =