make 'dW' motion use transition function that is specific for deleting, and add a test to ensure that 'dW' does not delete a newline when it is not on a newline character
This commit is contained in:
@@ -64,6 +64,7 @@ struct
|
|||||||
|
|
||||||
(* equivalent of vi's 'W' command *)
|
(* equivalent of vi's 'W' command *)
|
||||||
val nextWORD = ViCapsWordDfa.startOfNextWORD
|
val nextWORD = ViCapsWordDfa.startOfNextWORD
|
||||||
|
val nextWORDForDelete = ViCapsWordDfa.startOfNextWORDForDelete
|
||||||
|
|
||||||
(* equivalent of vi's 'b' command *)
|
(* equivalent of vi's 'b' command *)
|
||||||
val prevWord = ViWordDfa.startOfCurrentWord
|
val prevWord = ViWordDfa.startOfCurrentWord
|
||||||
|
|||||||
@@ -341,6 +341,20 @@ struct
|
|||||||
deleteAndFinish (app, cursorIdx, length, buffer, time)
|
deleteAndFinish (app, cursorIdx, length, buffer, time)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun deleteWORD (app as {buffer, ...}: app_type, count, time) =
|
||||||
|
if #textLength buffer = 1 then
|
||||||
|
NormalFinish.clearMode app
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val {buffer, cursorIdx, ...} = app
|
||||||
|
|
||||||
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
|
val high = Cursor.nextWORDForDelete (buffer, cursorIdx, count)
|
||||||
|
val length = high - cursorIdx
|
||||||
|
in
|
||||||
|
deleteAndFinish (app, cursorIdx, length, buffer, time)
|
||||||
|
end
|
||||||
|
|
||||||
fun deleteByDfa (app as {buffer, ...}: app_type, count, fMove, time) =
|
fun deleteByDfa (app as {buffer, ...}: app_type, count, fMove, time) =
|
||||||
if #textLength buffer = 1 then
|
if #textLength buffer = 1 then
|
||||||
NormalFinish.clearMode app
|
NormalFinish.clearMode app
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ struct
|
|||||||
| #"j" => NormalDelete.deleteLineDown (app, count, time)
|
| #"j" => NormalDelete.deleteLineDown (app, count, time)
|
||||||
| #"k" => NormalDelete.deleteLineBack (app, count, time)
|
| #"k" => NormalDelete.deleteLineBack (app, count, time)
|
||||||
| #"w" => NormalDelete.deleteWord (app, count, time)
|
| #"w" => NormalDelete.deleteWord (app, count, time)
|
||||||
| #"W" => NormalDelete.deleteByDfa (app, count, Cursor.nextWORD, time)
|
| #"W" => NormalDelete.deleteWORD (app, count, time)
|
||||||
| #"b" => NormalDelete.deleteByDfa (app, count, Cursor.prevWord, time)
|
| #"b" => NormalDelete.deleteByDfa (app, count, Cursor.prevWord, time)
|
||||||
| #"B" => NormalDelete.deleteByDfa (app, count, Cursor.prevWORD, time)
|
| #"B" => NormalDelete.deleteByDfa (app, count, Cursor.prevWORD, time)
|
||||||
| #"e" =>
|
| #"e" =>
|
||||||
@@ -347,7 +347,7 @@ struct
|
|||||||
| #"j" => NormalYankDelete.deleteLineDown (app, count, time)
|
| #"j" => NormalYankDelete.deleteLineDown (app, count, time)
|
||||||
| #"k" => NormalYankDelete.deleteLineBack (app, count, time)
|
| #"k" => NormalYankDelete.deleteLineBack (app, count, time)
|
||||||
| #"w" => NormalYankDelete.deleteWord (app, count, time)
|
| #"w" => NormalYankDelete.deleteWord (app, count, time)
|
||||||
| #"W" => NormalYankDelete.deleteByDfa (app, count, Cursor.nextWORD, time)
|
| #"W" => NormalYankDelete.deleteWORD (app, count, time)
|
||||||
| #"b" => NormalYankDelete.deleteByDfa (app, count, Cursor.prevWord, time)
|
| #"b" => NormalYankDelete.deleteByDfa (app, count, Cursor.prevWord, time)
|
||||||
| #"B" => NormalYankDelete.deleteByDfa (app, count, Cursor.prevWORD, time)
|
| #"B" => NormalYankDelete.deleteByDfa (app, count, Cursor.prevWORD, time)
|
||||||
| #"e" =>
|
| #"e" =>
|
||||||
|
|||||||
@@ -1197,8 +1197,29 @@ struct
|
|||||||
in
|
in
|
||||||
Expect.isTrue (stringsAreExpected andalso cursorsAreExpected)
|
Expect.isTrue (stringsAreExpected andalso cursorsAreExpected)
|
||||||
end)
|
end)
|
||||||
|
, test "does not delete newline following WORD" (fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val originalString = "hello\nworld\nagain\n"
|
||||||
|
val app = TestUtils.init originalString
|
||||||
|
val app = AppWith.idx (app, 0)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dW")
|
||||||
|
|
||||||
|
(* assert *)
|
||||||
|
val expectedString = "\nworld\nagain\n"
|
||||||
|
val expectedCursor = 0
|
||||||
|
|
||||||
|
val actualString = LineGap.toString buffer
|
||||||
|
|
||||||
|
val stringIsExpected = expectedString = actualString
|
||||||
|
val cursorIsExpected = expectedCursor = cursorIdx
|
||||||
|
in
|
||||||
|
Expect.isTrue (stringIsExpected andalso cursorIsExpected)
|
||||||
|
end)
|
||||||
, test
|
, test
|
||||||
"deletes newline when there is a newline after current word \
|
"does not delete newline when there is a newline after current word \
|
||||||
\and there is another word following that newline"
|
\and there is another word following that newline"
|
||||||
(fn _ =>
|
(fn _ =>
|
||||||
let
|
let
|
||||||
@@ -1211,8 +1232,8 @@ struct
|
|||||||
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dW")
|
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dW")
|
||||||
|
|
||||||
(* assert *)
|
(* assert *)
|
||||||
val expectedString = "hworld\nagain\n"
|
val expectedString = "h\nworld\nagain\n"
|
||||||
val expectedCursor = 1
|
val expectedCursor = 0
|
||||||
|
|
||||||
val actualString = LineGap.toString buffer
|
val actualString = LineGap.toString buffer
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user