diff --git a/fcore/normal-mode/make-normal-delete.sml b/fcore/normal-mode/make-normal-delete.sml index 17295d7..b17c299 100644 --- a/fcore/normal-mode/make-normal-delete.sml +++ b/fcore/normal-mode/make-normal-delete.sml @@ -677,34 +677,38 @@ struct deleteAndFinish (app, low, length, buffer, time) end + fun finishDeleteToChr (app, buffer, cursorIdx, otherIdx, time) = + let + val low = Int.min (cursorIdx, otherIdx) + val high = Int.max (cursorIdx, otherIdx) + val length = high - low + in + deleteAndFinish (app, low, length, buffer, time) + end + fun helpDeleteToChr (app: app_type, buffer, cursorIdx, otherIdx, count, fMove, fInc, chr, time) = if count = 0 then - let - val low = Int.min (cursorIdx, otherIdx) - val high = Int.max (cursorIdx, otherIdx) - val length = high - low - in - deleteAndFinish (app, low, length, buffer, time) - end + finishDeleteToChr (app, buffer, cursorIdx, otherIdx, time) else let val buffer = LineGap.goToIdx (otherIdx, buffer) val newOtherIdx = fMove (buffer, otherIdx, chr) - val newCount = if newOtherIdx = otherIdx then 0 else count - 1 - val newOtherIdx = fInc (newOtherIdx, 1) in - helpDeleteToChr - ( app - , buffer - , cursorIdx - , newOtherIdx - , newCount - , fMove - , fInc - , chr - , time - ) + if otherIdx = newOtherIdx then + finishDeleteToChr (app, buffer, cursorIdx, otherIdx, time) + else + helpDeleteToChr + ( app + , buffer + , cursorIdx + , fInc (newOtherIdx, 1) + , count - 1 + , fMove + , fInc + , chr + , time + ) end fun deleteToChr (app: app_type, count, fMove, fInc, chr, time) = diff --git a/test/normal-delete.sml b/test/normal-delete.sml index 586c511..89ee54a 100644 --- a/test/normal-delete.sml +++ b/test/normal-delete.sml @@ -3531,6 +3531,51 @@ struct (actualString = expectedString andalso cursorIdx = expectedCursorIdx) end) + , test + "deletes from cursor's position to second occurrence of \ + \if motion has a count of 2" + (fn _ => + let + (* arrange *) + val originalString = "hello\nworld\n" + val app = TestUtils.init originalString + val app = AppWith.idx (app, 0) + + (* act *) + val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "2dfo") + + (* assert *) + val actualString = LineGap.toString buffer + val expectedString = "rld\n" + val expectedCursorIdx = 0 + in + Expect.isTrue + (actualString = expectedString + andalso cursorIdx = expectedCursorIdx) + end) + , test + "deletes from cursor's position to last occurrence of \ + \if motion has a count greater than \ + \the number of occurences of , after the cursor" + (fn _ => + let + (* arrange *) + val originalString = "hello\nworld\n" + val app = TestUtils.init originalString + val app = AppWith.idx (app, 0) + + (* act *) + val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "99dfl") + + (* assert *) + val actualString = LineGap.toString buffer + val expectedString = "d\n" + val expectedCursorIdx = 0 + in + Expect.isTrue + (actualString = expectedString + andalso cursorIdx = expectedCursorIdx) + end) ] val tests = diff --git a/todo.md b/todo.md index 8dac8d1..a597c56 100644 --- a/todo.md +++ b/todo.md @@ -1,7 +1,6 @@ # To-do list - Add tests for: - - `df` - `dF` - `dt` - `dT`