@@ -463,3 +463,42 @@ describe("autoJoin", () => {
463
463
autoJoin ( lift , [ "bullet_list" ] ) ,
464
464
doc ( ul ( li ( p ( "a" ) ) , li ( p ( "b" ) ) , li ( p ( "c" ) ) ) ) ) )
465
465
} )
466
+
467
+ describe ( "toggleMark" , ( ) => {
468
+ let toggleEm = toggleMark ( schema . marks . em ) , toggleStrong = toggleMark ( schema . marks . strong )
469
+
470
+ it ( "can add a mark" , ( ) => {
471
+ apply ( doc ( p ( "one <a>two<b>" ) ) , toggleEm ,
472
+ doc ( p ( "one " , em ( "two" ) ) ) )
473
+ } )
474
+
475
+ it ( "can stack marks" , ( ) => {
476
+ apply ( doc ( p ( "one <a>tw" , strong ( "o<b>" ) ) ) , toggleEm ,
477
+ doc ( p ( "one " , em ( "tw" , strong ( "o" ) ) ) ) )
478
+ } )
479
+
480
+ it ( "can remove marks" , ( ) => {
481
+ apply ( doc ( p ( em ( "one <a>two<b>" ) ) ) , toggleEm ,
482
+ doc ( p ( em ( "one " ) , "two" ) ) )
483
+ } )
484
+
485
+ it ( "can toggle pending marks" , ( ) => {
486
+ let state = mkState ( doc ( p ( "hell<a>o" ) ) )
487
+ toggleEm ( state , tr => state = state . apply ( tr ) )
488
+ ist ( state . storedMarks . length , 1 )
489
+ toggleStrong ( state , tr => state = state . apply ( tr ) )
490
+ ist ( state . storedMarks . length , 2 )
491
+ toggleEm ( state , tr => state = state . apply ( tr ) )
492
+ ist ( state . storedMarks . length , 1 )
493
+ } )
494
+
495
+ it ( "skips whitespace at selection ends when adding marks" , ( ) => {
496
+ apply ( doc ( p ( "one<a> two <b>three" ) ) , toggleEm ,
497
+ doc ( p ( "one " , em ( "two" ) , " three" ) ) )
498
+ } )
499
+
500
+ it ( "doesn't skip whitespace-only selections" , ( ) => {
501
+ apply ( doc ( p ( "one<a> <b>two" ) ) , toggleEm ,
502
+ doc ( p ( "one" , em ( " " ) , "two" ) ) )
503
+ } )
504
+ } )
0 commit comments