if 'MakeNormalDelete.deleteLine' deletes to the end of the file such that there is no newline at the end, then append a newline. This makes one of the tests we have pass.

This commit is contained in:
2025-09-24 13:05:13 +01:00
parent 222a9aa43c
commit 80078196e0
3 changed files with 46 additions and 1 deletions

View File

@@ -354,11 +354,31 @@ struct
val finishIdx = Cursor.viDlr (buffer, cursorIdx, count) + 2
val length = finishIdx - startIdx
val textLengthBeforeDelete = #textLength buffer
val buffer = LineGap.goToIdx (startIdx, buffer)
val initialMsg = Fn.initMsgs (startIdx, length, buffer)
val buffer = LineGap.delete (startIdx, length, buffer)
in
finishAfterDeletingBuffer (app, startIdx, buffer, time, initialMsg)
if finishIdx >= textLengthBeforeDelete - 1 then
(* we deleted to the end of the buffer.
* Let's check if there is a newline at the end
* and insert one if there isn't. *)
let
val lastPosAfterDelete = #textLength buffer - 1
val buffer = LineGap.goToIdx (lastPosAfterDelete, buffer)
val buffer =
if lastPosAfterDelete < 0 then
LineGap.append ("\n", buffer)
else if Cursor.isCursorAtStartOfLine (buffer, lastPosAfterDelete) then
buffer
else
LineGap.append ("\n", buffer)
in
finishAfterDeletingBuffer (app, startIdx, buffer, time, initialMsg)
end
else
finishAfterDeletingBuffer (app, startIdx, buffer, time, initialMsg)
end
fun finishDeleteLineBack (app, buffer, lineIdx, length, endOfLine, time) =

View File

@@ -1,2 +1,3 @@
hello
world

View File

@@ -312,6 +312,30 @@ struct
in
Expect.isTrue (stringIsExpected andalso cursorIdxIsExpected)
end)
, test
"deletes when cursor is on first line and there are at least two lines"
(fn _ =>
let
(* arrange *)
val originalString = "hello\nworld\n"
val originalIdx = 0
val app = TestUtils.init originalString
val app = AppWith.idx (app, originalIdx)
(* act *)
val {cursorIdx, buffer, ...} = TestUtils.updateMany (app, "dj")
(* assert *)
val expectedString = "\n"
val actualString = LineGap.toString buffer
val stringIsExpected = expectedString = actualString
val expectedCursorIdx = 0
val cursorIdxIsExpected = expectedCursorIdx = cursorIdx
in
Expect.isTrue (stringIsExpected andalso cursorIdxIsExpected)
end)
, test
"deletes first two lines when there are three lines \
\and cursor is on first line"