@@ -473,7 +473,7 @@ describe("vim motion handler", () => {
473473 const w = createEvent ( "w" )
474474 expect ( ctx . handler . handleKey ( w . event ) ) . toBe ( true )
475475 expect ( w . prevented ( ) ) . toBe ( true )
476- expect ( ctx . textarea . cursorOffset ) . toBe ( 4 )
476+ expect ( ctx . textarea . cursorOffset ) . toBe ( 3 )
477477
478478 const upperW = createEvent ( "W" )
479479 expect ( ctx . handler . handleKey ( upperW . event ) ) . toBe ( true )
@@ -574,11 +574,36 @@ describe("vim motion handler", () => {
574574 expect ( ctx . textarea . cursorOffset ) . toBe ( 0 )
575575 } )
576576
577- test ( "b skips punctuation to previous word" , ( ) => {
577+ test ( "b treats punctuation as its own word" , ( ) => {
578578 const ctx = createHandler ( "foo,bar" )
579579 ctx . textarea . cursorOffset = 4
580+
580581 ctx . handler . handleKey ( createEvent ( "b" ) . event )
581- expect ( ctx . textarea . cursorOffset ) . toBe ( 0 )
582+ expect ( ctx . textarea . cursorOffset ) . toBe ( 3 )
583+ } )
584+
585+ test ( "w lands on trailing punctuation" , ( ) => {
586+ const ctx = createHandler ( "changed?" )
587+ ctx . textarea . cursorOffset = 0
588+
589+ ctx . handler . handleKey ( createEvent ( "w" ) . event )
590+ expect ( ctx . textarea . cursorOffset ) . toBe ( 7 )
591+ } )
592+
593+ test ( "w advances from punctuation to next word" , ( ) => {
594+ const ctx = createHandler ( "changed? next" )
595+ ctx . textarea . cursorOffset = 7
596+
597+ ctx . handler . handleKey ( createEvent ( "w" ) . event )
598+ expect ( ctx . textarea . cursorOffset ) . toBe ( 9 )
599+ } )
600+
601+ test ( "W treats punctuation as part of big word" , ( ) => {
602+ const ctx = createHandler ( "changed? next" )
603+ ctx . textarea . cursorOffset = 0
604+
605+ ctx . handler . handleKey ( createEvent ( "W" ) . event )
606+ expect ( ctx . textarea . cursorOffset ) . toBe ( 9 )
582607 } )
583608
584609 test ( "0 moves to line beginning" , ( ) => {
@@ -1258,7 +1283,7 @@ describe("vim motion handler", () => {
12581283 expect ( ctx . state . pending ( ) ) . toBe ( "" )
12591284 } )
12601285
1261- test ( "cw deletes to next word and enters insert" , ( ) => {
1286+ test ( "cw changes to end of word and enters insert" , ( ) => {
12621287 const ctx = createHandler ( "hello world test" )
12631288 ctx . textarea . cursorOffset = 0
12641289
@@ -1269,10 +1294,73 @@ describe("vim motion handler", () => {
12691294 const w = createEvent ( "w" )
12701295 expect ( ctx . handler . handleKey ( w . event ) ) . toBe ( true )
12711296 expect ( w . prevented ( ) ) . toBe ( true )
1272- expect ( ctx . textarea . plainText ) . toBe ( "world test" )
1297+ expect ( ctx . textarea . plainText ) . toBe ( " world test" )
12731298 expect ( ctx . textarea . cursorOffset ) . toBe ( 0 )
12741299 expect ( ctx . state . mode ( ) ) . toBe ( "insert" )
12751300 expect ( ctx . state . pending ( ) ) . toBe ( "" )
1301+ expect ( ctx . state . register ( ) ) . toEqual ( { text : "hello" , linewise : false } )
1302+ } )
1303+
1304+ test ( "cw from mid-word changes to end of word" , ( ) => {
1305+ const ctx = createHandler ( "hello world" )
1306+ ctx . textarea . cursorOffset = 2
1307+
1308+ ctx . handler . handleKey ( createEvent ( "c" ) . event )
1309+ ctx . handler . handleKey ( createEvent ( "w" ) . event )
1310+ expect ( ctx . textarea . plainText ) . toBe ( "he world" )
1311+ expect ( ctx . textarea . cursorOffset ) . toBe ( 2 )
1312+ expect ( ctx . state . mode ( ) ) . toBe ( "insert" )
1313+ expect ( ctx . state . register ( ) ) . toEqual ( { text : "llo" , linewise : false } )
1314+ } )
1315+
1316+ test ( "cw on punctuation changes punctuation word" , ( ) => {
1317+ const ctx = createHandler ( "foo!!!bar" )
1318+ ctx . textarea . cursorOffset = 3
1319+
1320+ ctx . handler . handleKey ( createEvent ( "c" ) . event )
1321+ ctx . handler . handleKey ( createEvent ( "w" ) . event )
1322+ expect ( ctx . textarea . plainText ) . toBe ( "foobar" )
1323+ expect ( ctx . textarea . cursorOffset ) . toBe ( 3 )
1324+ expect ( ctx . state . mode ( ) ) . toBe ( "insert" )
1325+ expect ( ctx . state . register ( ) ) . toEqual ( { text : "!!!" , linewise : false } )
1326+ } )
1327+
1328+ test ( "cw from whitespace changes through next word start" , ( ) => {
1329+ const ctx = createHandler ( "hello world" )
1330+ ctx . textarea . cursorOffset = 5
1331+
1332+ ctx . handler . handleKey ( createEvent ( "c" ) . event )
1333+ ctx . handler . handleKey ( createEvent ( "w" ) . event )
1334+ expect ( ctx . textarea . plainText ) . toBe ( "helloworld" )
1335+ expect ( ctx . textarea . cursorOffset ) . toBe ( 5 )
1336+ expect ( ctx . state . mode ( ) ) . toBe ( "insert" )
1337+ expect ( ctx . state . register ( ) ) . toEqual ( { text : " " , linewise : false } )
1338+ } )
1339+
1340+ test ( "cW changes through end of big word and enters insert" , ( ) => {
1341+ const ctx = createHandler ( "foo.bar baz" )
1342+ ctx . textarea . cursorOffset = 0
1343+
1344+ ctx . handler . handleKey ( createEvent ( "c" ) . event )
1345+ const w = createEvent ( "W" )
1346+ expect ( ctx . handler . handleKey ( w . event ) ) . toBe ( true )
1347+ expect ( w . prevented ( ) ) . toBe ( true )
1348+ expect ( ctx . textarea . plainText ) . toBe ( " baz" )
1349+ expect ( ctx . textarea . cursorOffset ) . toBe ( 0 )
1350+ expect ( ctx . state . mode ( ) ) . toBe ( "insert" )
1351+ expect ( ctx . state . register ( ) ) . toEqual ( { text : "foo.bar" , linewise : false } )
1352+ } )
1353+
1354+ test ( "cW from whitespace changes through next big word start" , ( ) => {
1355+ const ctx = createHandler ( "foo.bar baz" )
1356+ ctx . textarea . cursorOffset = 7
1357+
1358+ ctx . handler . handleKey ( createEvent ( "c" ) . event )
1359+ ctx . handler . handleKey ( createEvent ( "W" ) . event )
1360+ expect ( ctx . textarea . plainText ) . toBe ( "foo.barbaz" )
1361+ expect ( ctx . textarea . cursorOffset ) . toBe ( 7 )
1362+ expect ( ctx . state . mode ( ) ) . toBe ( "insert" )
1363+ expect ( ctx . state . register ( ) ) . toEqual ( { text : " " , linewise : false } )
12761364 } )
12771365
12781366 test ( "pending c clears on escape" , ( ) => {
@@ -1630,6 +1718,42 @@ describe("vim motion handler", () => {
16301718 expect ( ctx . textarea . cursorOffset ) . toBe ( 0 )
16311719 } )
16321720
1721+ test ( "dw stops before trailing punctuation" , ( ) => {
1722+ const ctx = createHandler ( "changed?" )
1723+ ctx . textarea . cursorOffset = 0
1724+
1725+ ctx . handler . handleKey ( createEvent ( "d" ) . event )
1726+ ctx . handler . handleKey ( createEvent ( "w" ) . event )
1727+ expect ( ctx . textarea . plainText ) . toBe ( "?" )
1728+ expect ( ctx . textarea . cursorOffset ) . toBe ( 0 )
1729+ expect ( ctx . state . register ( ) ) . toEqual ( { text : "changed" , linewise : false } )
1730+ } )
1731+
1732+ test ( "dW deletes through next big word start" , ( ) => {
1733+ const ctx = createHandler ( "foo.bar baz" )
1734+ ctx . textarea . cursorOffset = 0
1735+
1736+ ctx . handler . handleKey ( createEvent ( "d" ) . event )
1737+ const w = createEvent ( "W" )
1738+ expect ( ctx . handler . handleKey ( w . event ) ) . toBe ( true )
1739+ expect ( w . prevented ( ) ) . toBe ( true )
1740+ expect ( ctx . textarea . plainText ) . toBe ( "baz" )
1741+ expect ( ctx . textarea . cursorOffset ) . toBe ( 0 )
1742+ expect ( ctx . state . pending ( ) ) . toBe ( "" )
1743+ expect ( ctx . state . register ( ) ) . toEqual ( { text : "foo.bar " , linewise : false } )
1744+ } )
1745+
1746+ test ( "dW at final big word deletes to end" , ( ) => {
1747+ const ctx = createHandler ( "foo.bar" )
1748+ ctx . textarea . cursorOffset = 0
1749+
1750+ ctx . handler . handleKey ( createEvent ( "d" ) . event )
1751+ ctx . handler . handleKey ( createEvent ( "W" ) . event )
1752+ expect ( ctx . textarea . plainText ) . toBe ( "" )
1753+ expect ( ctx . textarea . cursorOffset ) . toBe ( 0 )
1754+ expect ( ctx . state . register ( ) ) . toEqual ( { text : "foo.bar" , linewise : false } )
1755+ } )
1756+
16331757 test ( "db deletes to current word start" , ( ) => {
16341758 const ctx = createHandler ( "hello world test" )
16351759 ctx . textarea . cursorOffset = 8
@@ -2245,6 +2369,46 @@ describe("vim motion handler", () => {
22452369 expect ( ctx . textarea . plainText ) . toBe ( "hello world" )
22462370 } )
22472371
2372+ test ( "yw stops before trailing punctuation" , ( ) => {
2373+ const ctx = createHandler ( "changed?" )
2374+ ctx . textarea . cursorOffset = 0
2375+
2376+ ctx . handler . handleKey ( createEvent ( "y" ) . event )
2377+ ctx . handler . handleKey ( createEvent ( "w" ) . event )
2378+ expect ( ctx . state . register ( ) ) . toEqual ( { text : "changed" , linewise : false } )
2379+ expect ( ctx . textarea . cursorOffset ) . toBe ( 0 )
2380+ expect ( ctx . textarea . plainText ) . toBe ( "changed?" )
2381+ } )
2382+
2383+ test ( "yW yanks through next big word start" , ( ) => {
2384+ const ctx = createHandler ( "foo.bar baz" )
2385+ ctx . textarea . cursorOffset = 0
2386+
2387+ ctx . handler . handleKey ( createEvent ( "y" ) . event )
2388+ const w = createEvent ( "W" )
2389+ expect ( ctx . handler . handleKey ( w . event ) ) . toBe ( true )
2390+ expect ( w . prevented ( ) ) . toBe ( true )
2391+ expect ( ctx . state . register ( ) ) . toEqual ( { text : "foo.bar " , linewise : false } )
2392+ expect ( ctx . textarea . cursorOffset ) . toBe ( 0 )
2393+ expect ( ctx . textarea . plainText ) . toBe ( "foo.bar baz" )
2394+ expect ( ctx . state . pending ( ) ) . toBe ( "" )
2395+ } )
2396+
2397+ test ( "yW flashes yanked big word span" , ( ) => {
2398+ const spans : Array < { start : number ; end : number } > = [ ]
2399+ const ctx = createHandler ( "foo.bar baz" , {
2400+ flash ( span ) {
2401+ spans . push ( span )
2402+ } ,
2403+ } )
2404+ ctx . textarea . cursorOffset = 0
2405+
2406+ ctx . handler . handleKey ( createEvent ( "y" ) . event )
2407+ ctx . handler . handleKey ( createEvent ( "W" ) . event )
2408+
2409+ expect ( spans ) . toEqual ( [ { start : 0 , end : 8 } ] )
2410+ } )
2411+
22482412 test ( "yw flashes yanked word span" , ( ) => {
22492413 const spans : Array < { start : number ; end : number } > = [ ]
22502414 const ctx = createHandler ( "hello world" , {
@@ -3821,7 +3985,7 @@ describe("vim undo redo", () => {
38213985 ctx . textarea . insertText ( "hi" )
38223986 ctx . handler . handleKey ( createEvent ( "escape" ) . event )
38233987
3824- expect ( ctx . textarea . plainText ) . toBe ( "hiworld " )
3988+ expect ( ctx . textarea . plainText ) . toBe ( "hi world " )
38253989
38263990 ctx . handler . handleKey ( createEvent ( "u" ) . event )
38273991 expect ( ctx . textarea . plainText ) . toBe ( "hello world" )
0 commit comments