add test for 'dw' case: when we use 'dw' on last word in buffer, and there is no newline after last word, we delete last word fully
This commit is contained in:
@@ -272,10 +272,30 @@ struct
|
|||||||
|
|
||||||
fun finishDeleteByDfa (app, low, high, buffer, time) =
|
fun finishDeleteByDfa (app, low, high, buffer, time) =
|
||||||
let
|
let
|
||||||
val length = high - low
|
|
||||||
val buffer = LineGap.goToIdx (high, buffer)
|
val buffer = LineGap.goToIdx (high, buffer)
|
||||||
|
val high =
|
||||||
|
(* by default, we have a newline at the end of the buffer.
|
||||||
|
* However, we also support the case where there is no newline
|
||||||
|
* at the end of the buffer.
|
||||||
|
* The first case is supported by default,
|
||||||
|
* but we have to increment the textLength if the buffer
|
||||||
|
* does not end with a newline, to make sure that
|
||||||
|
* we delete the last character. *)
|
||||||
|
if
|
||||||
|
high = #textLength buffer - 1
|
||||||
|
andalso not (Cursor.isCursorAtStartOfLine (buffer, high))
|
||||||
|
then #textLength buffer
|
||||||
|
else high
|
||||||
|
|
||||||
|
val length = high - low
|
||||||
val initialMsg = Fn.initMsgs (low, length, buffer)
|
val initialMsg = Fn.initMsgs (low, length, buffer)
|
||||||
val buffer = LineGap.delete (low, length, buffer)
|
val buffer = LineGap.delete (low, length, buffer)
|
||||||
|
|
||||||
|
(* if we deleted all text in the buffer,
|
||||||
|
* then make sure that we append a newline at the end
|
||||||
|
* so that the buffer contains at least one character *)
|
||||||
|
val buffer =
|
||||||
|
if #textLength buffer = 0 then LineGap.append ("\n", buffer) else buffer
|
||||||
in
|
in
|
||||||
if low >= #textLength buffer - 1 andalso #textLength buffer > 0 then
|
if low >= #textLength buffer - 1 andalso #textLength buffer > 0 then
|
||||||
(* edge case:
|
(* edge case:
|
||||||
|
|||||||
@@ -1084,6 +1084,29 @@ struct
|
|||||||
in
|
in
|
||||||
Expect.isTrue (stringIsExpected andalso cursorIsExpected)
|
Expect.isTrue (stringIsExpected andalso cursorIsExpected)
|
||||||
end)
|
end)
|
||||||
|
, test
|
||||||
|
"deletes last char when on last word \
|
||||||
|
\and there is no newline after current word"
|
||||||
|
(fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val app = TestUtils.init "hello world"
|
||||||
|
val app = AppWith.idx (app, 6)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dw")
|
||||||
|
|
||||||
|
(* assert *)
|
||||||
|
val expectedString = "hello "
|
||||||
|
val actualString = LineGap.toString buffer
|
||||||
|
|
||||||
|
val expectedIdx = 5
|
||||||
|
|
||||||
|
val stringIsExpected = expectedString = actualString
|
||||||
|
val cursorIsExpected = cursorIdx = expectedIdx
|
||||||
|
in
|
||||||
|
Expect.isTrue (stringIsExpected andalso cursorIsExpected)
|
||||||
|
end)
|
||||||
]
|
]
|
||||||
|
|
||||||
val dWDelete = describe "delete motion 'dW'"
|
val dWDelete = describe "delete motion 'dW'"
|
||||||
|
|||||||
Reference in New Issue
Block a user