add failing test for 'dj' motion, and progress reimplementing 'MakeNormalDelete.deleteLine'

This commit is contained in:
2025-09-25 06:11:36 +01:00
parent d25a06a9ed
commit b73117d075
2 changed files with 27 additions and 2 deletions

View File

@@ -361,14 +361,17 @@ struct
else endLineIdx
val buffer = LineGap.goToIdx (endLineIdx, buffer)
in
if Cursor.isOnNewlineAfterChr (buffer, endLineIdx) then
if Cursor.isCursorAtStartOfLine (buffer, endLineIdx) then
let
val endLineIdx = endLineIdx + 1
val endLineIdx =
if endLineIdx = #textLength buffer - 1 then endLineIdx - 1
else endLineIdx + 1
val length = endLineIdx - startIdx
val initialMsg = Fn.initMsgs (startIdx, length, buffer)
val buffer = LineGap.delete (startIdx, length, buffer)
(* just need to reposition the cursor *)
val ss = LineGap.toString buffer
val ss = String.toCString ss ^ "\n"
val () = print ss

View File

@@ -436,6 +436,28 @@ struct
in
Expect.isTrue (stringIsExpected andalso cursorIdxIsExpected)
end)
, test "deletes two lines when cursor is on a newline" (fn _ =>
let
(* arrange *)
val originalString = "\nhello\nworld\ntrello\brillo\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 = "world\ntrello\nbrillo\n"
val actualString = LineGap.toString buffer
val stringIsExpected = expectedString = actualString
val expectedCursorIdx = 0
val cursorIdxIsExpected = expectedCursorIdx = cursorIdx
in
Expect.isTrue (stringIsExpected andalso cursorIdxIsExpected)
end)
]
val tests = [dhDelete, dlDelete, djDelete]