amend implementation of 'yw' so that we do not yank newline following last word in line, if we are trying to yank last word
This commit is contained in:
@@ -203,9 +203,13 @@ struct
|
|||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
|
|
||||||
val high = fMove (buffer, cursorIdx, count)
|
val high = fMove (buffer, cursorIdx, count)
|
||||||
val high = if high = #textLength buffer then high - 1 else high
|
val beforeHigh = high - 1
|
||||||
|
val buffer = LineGap.goToIdx (beforeHigh, buffer)
|
||||||
|
|
||||||
|
val high =
|
||||||
|
if Cursor.isOnNewlineAfterChr (buffer, beforeHigh) then beforeHigh
|
||||||
|
else high
|
||||||
|
|
||||||
val buffer = LineGap.goToIdx (high, buffer)
|
|
||||||
val length = high - cursorIdx
|
val length = high - cursorIdx
|
||||||
val str = LineGap.substring (cursorIdx, length, buffer)
|
val str = LineGap.substring (cursorIdx, length, buffer)
|
||||||
in
|
in
|
||||||
|
|||||||
@@ -650,6 +650,20 @@ struct
|
|||||||
end)
|
end)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
fun yankSeconWordAlpha (pos, expectedString) =
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val originalString = "hello world again\n"
|
||||||
|
val app = TestUtils.init originalString
|
||||||
|
val app = AppWith.idx (app, pos)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val app = TestUtils.updateMany (app, "yw")
|
||||||
|
in
|
||||||
|
(* assert *)
|
||||||
|
TestUtils.expectYank (app, expectedString)
|
||||||
|
end
|
||||||
|
|
||||||
val ywYank = describe "yank motion 'yw'"
|
val ywYank = describe "yank motion 'yw'"
|
||||||
[ test "yanks last character when cursor is on last character of line"
|
[ test "yanks last character when cursor is on last character of line"
|
||||||
(fn _ =>
|
(fn _ =>
|
||||||
@@ -669,70 +683,34 @@ struct
|
|||||||
in
|
in
|
||||||
TestUtils.expectYank (app, expectedString)
|
TestUtils.expectYank (app, expectedString)
|
||||||
end)
|
end)
|
||||||
, test "deletes second word as expected when there are three words" (fn _ =>
|
, test
|
||||||
let
|
"yanks from second word up to (and excluding) third word \
|
||||||
(* arrange *)
|
\when cursor is on first character of second word"
|
||||||
val originalString = "hello world again\n"
|
(fn _ => yankSeconWordAlpha (6, "world "))
|
||||||
|
, test
|
||||||
val app = TestUtils.init originalString
|
"yanks from second character of second word \
|
||||||
|
\up to (and excluding) third word \
|
||||||
(* all the different positions the cursor can be
|
\when cursor is on second character of second word"
|
||||||
* on the second word *)
|
(fn _ => yankSeconWordAlpha (7, "orld "))
|
||||||
val app1 = AppWith.idx (app, 6)
|
, test
|
||||||
val app2 = AppWith.idx (app, 7)
|
"yanks from third character of second word \
|
||||||
val app3 = AppWith.idx (app, 8)
|
\up to (and excluding) third word \
|
||||||
val app4 = AppWith.idx (app, 9)
|
\when cursor is on third character of second word"
|
||||||
val app5 = AppWith.idx (app, 10)
|
(fn _ => yankSeconWordAlpha (8, "rld "))
|
||||||
|
, test
|
||||||
(* act *)
|
"yanks from fourth character of second word \
|
||||||
val newApp1 = TestUtils.updateMany (app1, "yw")
|
\up to (and excluding) third word \
|
||||||
val newApp2 = TestUtils.updateMany (app2, "yw")
|
\when cursor is on fourth character of second word"
|
||||||
val newApp3 = TestUtils.updateMany (app3, "yw")
|
(fn _ => yankSeconWordAlpha (9, "ld "))
|
||||||
val newApp4 = TestUtils.updateMany (app4, "yw")
|
, test
|
||||||
val newApp5 = TestUtils.updateMany (app5, "yw")
|
"yanks from fifth character of second word \
|
||||||
|
\up to (and excluding) third word \
|
||||||
(* assert *)
|
\when cursor is on fifth character of second word"
|
||||||
val expectedString1 = "hello again\n"
|
(fn _ => yankSeconWordAlpha (10, "d "))
|
||||||
val expectedString2 = "hello wagain\n"
|
, test
|
||||||
val expectedString3 = "hello woagain\n"
|
"yanks space when cursor is on space preceding an alpha char"
|
||||||
val expectedString4 = "hello woragain\n"
|
(fn _ => yankSeconWordAlpha (11, " "))
|
||||||
val expectedString5 = "hello worlagain\n"
|
, test "does not yank newline when cursor is on last word of line" (fn _ =>
|
||||||
|
|
||||||
val actualString1 = LineGap.toString (#buffer newApp1)
|
|
||||||
val actualString2 = LineGap.toString (#buffer newApp2)
|
|
||||||
val actualString3 = LineGap.toString (#buffer newApp3)
|
|
||||||
val actualString4 = LineGap.toString (#buffer newApp4)
|
|
||||||
val actualString5 = LineGap.toString (#buffer newApp5)
|
|
||||||
|
|
||||||
val stringsAreExpected =
|
|
||||||
expectedString1 = actualString1
|
|
||||||
andalso expectedString2 = actualString2
|
|
||||||
andalso expectedString3 = actualString3
|
|
||||||
andalso expectedString4 = actualString4
|
|
||||||
andalso expectedString5 = actualString5
|
|
||||||
|
|
||||||
val expectedCursor1 = 6
|
|
||||||
val expectedCursor2 = 7
|
|
||||||
val expectedCursor3 = 8
|
|
||||||
val expectedCursor4 = 9
|
|
||||||
val expectedCursor5 = 10
|
|
||||||
|
|
||||||
val actualCursor1 = #cursorIdx newApp1
|
|
||||||
val actualCursor2 = #cursorIdx newApp2
|
|
||||||
val actualCursor3 = #cursorIdx newApp3
|
|
||||||
val actualCursor4 = #cursorIdx newApp4
|
|
||||||
val actualCursor5 = #cursorIdx newApp5
|
|
||||||
|
|
||||||
val cursorsAreExpected =
|
|
||||||
expectedCursor1 = actualCursor1
|
|
||||||
andalso expectedCursor2 = actualCursor2
|
|
||||||
andalso expectedCursor3 = actualCursor3
|
|
||||||
andalso expectedCursor4 = actualCursor4
|
|
||||||
andalso expectedCursor5 = actualCursor5
|
|
||||||
in
|
|
||||||
Expect.isTrue (stringsAreExpected andalso cursorsAreExpected)
|
|
||||||
end)
|
|
||||||
, test "does not delete newline following word" (fn _ =>
|
|
||||||
let
|
let
|
||||||
(* arrange *)
|
(* arrange *)
|
||||||
val originalString = "hello\nworld\nagain\n"
|
val originalString = "hello\nworld\nagain\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user