add another test for 'df<char>' motion, checking that we leave a newline behind if the whole buffer is deleted

This commit is contained in:
2025-10-18 14:29:20 +01:00
parent 5d00da2cbb
commit bc44c7bcd0
2 changed files with 21 additions and 0 deletions

View File

@@ -728,6 +728,9 @@ struct
val initialMsg = Fn.initMsgs (cursorIdx, length, buffer) val initialMsg = Fn.initMsgs (cursorIdx, length, buffer)
val buffer = LineGap.delete (cursorIdx, length, buffer) val buffer = LineGap.delete (cursorIdx, length, buffer)
val buffer =
if #textLength buffer = 0 then LineGap.fromString "\n" else buffer
val buffer = LineGap.goToIdx (cursorIdx, buffer) val buffer = LineGap.goToIdx (cursorIdx, buffer)
val cursorIdx = val cursorIdx =
if Cursor.isOnNewlineAfterChr (buffer, cursorIdx) then cursorIdx - 1 if Cursor.isOnNewlineAfterChr (buffer, cursorIdx) then cursorIdx - 1

View File

@@ -3598,6 +3598,24 @@ struct
(actualString = expectedString (actualString = expectedString
andalso cursorIdx = expectedCursorIdx) andalso cursorIdx = expectedCursorIdx)
end) end)
, test "leaves a newline behind if whole buffer is deleted" (fn _ =>
let
(* arrange *)
val originalString = "hey hello\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, 0)
(* act *)
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dfo")
(* assert *)
val actualString = LineGap.toString buffer
val expectedString = "\n"
val expectedCursorIdx = 0
in
Expect.isTrue
(actualString = expectedString andalso cursorIdx = expectedCursorIdx)
end)
] ]
val dtDelete = describe "delete motion 'dt<char>'" val dtDelete = describe "delete motion 'dt<char>'"