reimplement 'df' motion as per previous commits, and add a new test for 'df' motion to check that cursor does not land on a 'newline following a non-newline' position, after deleting using 'df<char>'
This commit is contained in:
@@ -648,7 +648,7 @@ struct
|
|||||||
|
|
||||||
fun deleteToFirstNonSpaceChr (app: app_type, time) =
|
fun deleteToFirstNonSpaceChr (app: app_type, time) =
|
||||||
let
|
let
|
||||||
val {buffer, cursorIdx, windowWidth, windowHeight, startLine, ...} = app
|
val {buffer, cursorIdx, ...} = app
|
||||||
|
|
||||||
(* move LineGap and buffer to start of line *)
|
(* move LineGap and buffer to start of line *)
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
@@ -712,6 +712,31 @@ struct
|
|||||||
, time
|
, time
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun deleteToNextChr (app: app_type, count, chr, time) =
|
||||||
|
let
|
||||||
|
val {buffer, cursorIdx, ...} = app
|
||||||
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
|
val newCursorIdx =
|
||||||
|
Cursor.toNextChrNew (buffer, cursorIdx, {findChr = chr, count = count})
|
||||||
|
in
|
||||||
|
if newCursorIdx = ~1 then
|
||||||
|
NormalFinish.clearMode app
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val length = newCursorIdx - cursorIdx + 1
|
||||||
|
val buffer = LineGap.goToIdx (newCursorIdx, buffer)
|
||||||
|
val initialMsg = Fn.initMsgs (cursorIdx, length, buffer)
|
||||||
|
val buffer = LineGap.delete (cursorIdx, length, buffer)
|
||||||
|
|
||||||
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
|
val cursorIdx =
|
||||||
|
if Cursor.isOnNewlineAfterChr (buffer, cursorIdx) then cursorIdx - 1
|
||||||
|
else cursorIdx
|
||||||
|
in
|
||||||
|
finishAfterDeletingBuffer (app, cursorIdx, buffer, time, initialMsg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
fun deleteToStart (app: app_type, time) : AppType.app_type =
|
fun deleteToStart (app: app_type, time) : AppType.app_type =
|
||||||
let
|
let
|
||||||
val {cursorIdx, buffer, windowWidth, windowHeight, dfa, ...} = app
|
val {cursorIdx, buffer, windowWidth, windowHeight, dfa, ...} = app
|
||||||
|
|||||||
@@ -304,9 +304,7 @@ struct
|
|||||||
| #"T" =>
|
| #"T" =>
|
||||||
NormalDelete.deleteToChr
|
NormalDelete.deleteToChr
|
||||||
(app, 1, Cursor.tillPrevChr, op-, chrCmd, time)
|
(app, 1, Cursor.tillPrevChr, op-, chrCmd, time)
|
||||||
| #"f" =>
|
| #"f" => NormalDelete.deleteToNextChr (app, count, chrCmd, time)
|
||||||
NormalDelete.deleteToChr
|
|
||||||
(app, count, Cursor.toNextChr, op+, chrCmd, time)
|
|
||||||
| #"F" =>
|
| #"F" =>
|
||||||
NormalDelete.deleteToChr
|
NormalDelete.deleteToChr
|
||||||
(app, count, Cursor.toPrevChr, op-, chrCmd, time)
|
(app, count, Cursor.toPrevChr, op-, chrCmd, time)
|
||||||
@@ -560,18 +558,13 @@ struct
|
|||||||
* which can be made terminal by adding "w" or "e" at the end.
|
* which can be made terminal by adding "w" or "e" at the end.
|
||||||
* *)
|
* *)
|
||||||
case String.sub (str, strPos) of
|
case String.sub (str, strPos) of
|
||||||
#"t" =>
|
#"t" => NormalMove.tillNextChr (app, count, chrCmd)
|
||||||
(* to just before char, forward
|
|
||||||
* tillNextChr with count of 1 has same effect
|
|
||||||
* as tillNextChr with any count above 1
|
|
||||||
* so just hardcode 1 *)
|
|
||||||
NormalMove.tillNextChr (app, count, chrCmd)
|
|
||||||
| #"T" =>
|
| #"T" =>
|
||||||
(* to just before chr, backward *)
|
(* to just before chr, backward *)
|
||||||
parseMoveToChr (1, app, Cursor.tillPrevChr, chrCmd)
|
parseMoveToChr (1, app, Cursor.tillPrevChr, chrCmd)
|
||||||
| #"y" => ParseYank.parseYank (strPos, str, count, app, chrCmd, time)
|
| #"y" => ParseYank.parseYank (strPos, str, count, app, chrCmd, time)
|
||||||
| #"d" => ParseDelete.parseDelete (strPos, str, count, app, chrCmd, time)
|
| #"d" => ParseDelete.parseDelete (strPos, str, count, app, chrCmd, time)
|
||||||
| #"f" => (* to chr, forward *) NormalMove.toNextChr (app, count, chrCmd)
|
| #"f" => NormalMove.toNextChr (app, count, chrCmd)
|
||||||
| #"F" =>
|
| #"F" =>
|
||||||
(* to chr, backward *)
|
(* to chr, backward *)
|
||||||
parseMoveToChr (count, app, Cursor.toPrevChr, chrCmd)
|
parseMoveToChr (count, app, Cursor.toPrevChr, chrCmd)
|
||||||
|
|||||||
@@ -3576,6 +3576,28 @@ struct
|
|||||||
(actualString = expectedString
|
(actualString = expectedString
|
||||||
andalso cursorIdx = expectedCursorIdx)
|
andalso cursorIdx = expectedCursorIdx)
|
||||||
end)
|
end)
|
||||||
|
, test
|
||||||
|
"moves cursor back by one, when deletion range is \
|
||||||
|
\from a newline that follows a non-newline char"
|
||||||
|
(fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val originalString = "hey hello\n"
|
||||||
|
val app = TestUtils.init originalString
|
||||||
|
val app = AppWith.idx (app, 3)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dfo")
|
||||||
|
|
||||||
|
(* assert *)
|
||||||
|
val actualString = LineGap.toString buffer
|
||||||
|
val expectedString = "hey\n"
|
||||||
|
val expectedCursorIdx = 2
|
||||||
|
in
|
||||||
|
Expect.isTrue
|
||||||
|
(actualString = expectedString
|
||||||
|
andalso cursorIdx = expectedCursorIdx)
|
||||||
|
end)
|
||||||
]
|
]
|
||||||
|
|
||||||
val dtDelete = describe "delete motion 'dt<char>'"
|
val dtDelete = describe "delete motion 'dt<char>'"
|
||||||
|
|||||||
Reference in New Issue
Block a user