improve 'MakeNormalDelete.deleteByDfa' function by refraining from deleting the unix-style line ending, if DFA takes us past the ending

This commit is contained in:
2025-09-23 06:09:03 +01:00
parent 12bd30d9dd
commit 02ada5765b

View File

@@ -235,15 +235,13 @@ struct
val otherIdx = fMove (buffer, cursorIdx, count) val otherIdx = fMove (buffer, cursorIdx, count)
in in
if otherIdx > cursorIdx then if otherIdx > cursorIdx then
let (* prevent us from deleting last newline
val buffer = * to help us preserve unix-style line endings *)
if otherIdx > #textLength buffer - 1 then if otherIdx > #textLength buffer then
LineGap.append ("\n\n", buffer) finishDeleteByDfa
else (app, cursorIdx, #textLength buffer - 1, buffer, time)
buffer else
in
finishDeleteByDfa (app, cursorIdx, otherIdx, buffer, time) finishDeleteByDfa (app, cursorIdx, otherIdx, buffer, time)
end
else if otherIdx < cursorIdx then else if otherIdx < cursorIdx then
finishDeleteByDfa (app, otherIdx, cursorIdx, buffer, time) finishDeleteByDfa (app, otherIdx, cursorIdx, buffer, time)
else else
@@ -304,14 +302,11 @@ struct
val length = high - cursorIdx val length = high - cursorIdx
(* we might want to delete to the end of the file. (* we might want to delete to the end of the file.
* If so, we will append a double-newline. * If so, we will append a newline
* The second newline is to comply with Unix-style line endings * to restore Unix-style line endings *)
* and the first newline provides a place for our cursor to rest. *)
val buffer = val buffer =
if high > #textLength buffer - 1 then if high > #textLength buffer - 1 then LineGap.append ("\n", buffer)
LineGap.append ("\n\n", buffer) else buffer
else
buffer
val buffer = LineGap.goToIdx (high, buffer) val buffer = LineGap.goToIdx (high, buffer)
val initialMsg = Fn.initMsgs (cursorIdx, length, buffer) val initialMsg = Fn.initMsgs (cursorIdx, length, buffer)
@@ -349,7 +344,7 @@ struct
val buffer = val buffer =
if finishIdx >= textLengthBeforeDelete - 1 then if finishIdx >= textLengthBeforeDelete - 1 then
LineGap.append ("\n\n", buffer) LineGap.append ("\n", buffer)
else else
buffer buffer
in in