playroom 0.34.2 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/.github/workflows/preview-site.yml +3 -3
  2. package/.github/workflows/release.yml +3 -3
  3. package/.github/workflows/snapshot.yml +3 -3
  4. package/.github/workflows/validate.yml +5 -5
  5. package/.nvmrc +1 -1
  6. package/CHANGELOG.md +55 -0
  7. package/README.md +6 -0
  8. package/bin/cli.cjs +2 -1
  9. package/cypress/e2e/editor.cy.js +1 -1
  10. package/cypress/e2e/keymaps.cy.js +1507 -11
  11. package/cypress/e2e/scope.cy.js +1 -1
  12. package/cypress/e2e/smoke.cy.js +2 -2
  13. package/cypress/e2e/toolbar.cy.js +1 -2
  14. package/cypress/e2e/urlHandling.cy.js +4 -5
  15. package/cypress/support/utils.js +62 -54
  16. package/lib/makeWebpackConfig.js +0 -3
  17. package/lib/provideDefaultConfig.js +13 -2
  18. package/package.json +18 -17
  19. package/src/Playroom/CatchErrors/CatchErrors.tsx +5 -6
  20. package/src/Playroom/CodeEditor/CodeEditor.tsx +11 -0
  21. package/src/Playroom/CodeEditor/keymaps/comment.ts +326 -0
  22. package/src/Playroom/CodeEditor/keymaps/wrap.ts +4 -1
  23. package/src/Playroom/Frame.tsx +9 -5
  24. package/src/Playroom/FramesPanel/FramesPanel.css.ts +19 -0
  25. package/src/Playroom/FramesPanel/FramesPanel.tsx +89 -46
  26. package/src/Playroom/Preview.tsx +12 -3
  27. package/src/Playroom/PreviewPanel/PreviewPanel.tsx +1 -1
  28. package/src/Playroom/SettingsPanel/SettingsPanel.tsx +11 -7
  29. package/src/Playroom/Stack/Stack.css.ts +4 -35
  30. package/src/Playroom/Stack/Stack.tsx +2 -9
  31. package/src/Playroom/Toolbar/Toolbar.tsx +2 -2
  32. package/src/Playroom/sprinkles.css.ts +1 -0
  33. package/src/StoreContext/StoreContext.tsx +31 -6
  34. package/src/index.d.ts +2 -0
  35. package/src/utils/params.ts +5 -8
  36. package/src/utils/usePreviewUrl.ts +2 -1
  37. package/utils/index.d.ts +3 -0
  38. package/utils/index.js +21 -7
@@ -4,9 +4,13 @@ import {
4
4
  assertCodePaneContains,
5
5
  loadPlayroom,
6
6
  selectNextWords,
7
- selectLines,
7
+ selectNextLines,
8
8
  selectNextCharacters,
9
+ selectToStartOfLine,
9
10
  selectToEndOfLine,
11
+ moveToEndOfLine,
12
+ moveBy,
13
+ moveByWords,
10
14
  } from '../support/utils';
11
15
  import { isMac } from '../../src/utils/formatting';
12
16
 
@@ -16,15 +20,15 @@ const cmdPlus = (keyCombo) => {
16
20
  };
17
21
 
18
22
  describe('Keymaps', () => {
19
- beforeEach(() => {
20
- loadPlayroom(`
21
- <div>First line</div>
22
- <div>Second line</div>
23
- <div>Third line</div>
24
- `);
25
- });
26
-
27
23
  describe('swapLine', () => {
24
+ beforeEach(() => {
25
+ loadPlayroom(`
26
+ <div>First line</div>
27
+ <div>Second line</div>
28
+ <div>Third line</div>
29
+ `);
30
+ });
31
+
28
32
  it('should swap single lines up and down without a selection', () => {
29
33
  // Move the first line down
30
34
  typeCode('{alt+downArrow}');
@@ -67,7 +71,7 @@ describe('Keymaps', () => {
67
71
 
68
72
  it('should swap multiple lines up and down with a selection', () => {
69
73
  typeCode('{rightArrow}');
70
- selectLines(1);
74
+ selectNextLines(1);
71
75
  selectNextCharacters(3);
72
76
 
73
77
  typeCode('{alt+downArrow}');
@@ -89,6 +93,14 @@ describe('Keymaps', () => {
89
93
  });
90
94
 
91
95
  describe('duplicateLine', () => {
96
+ beforeEach(() => {
97
+ loadPlayroom(`
98
+ <div>First line</div>
99
+ <div>Second line</div>
100
+ <div>Third line</div>
101
+ `);
102
+ });
103
+
92
104
  it('should duplicate single lines up and down', () => {
93
105
  // Duplicate the first line down
94
106
  typeCode('{shift+alt+downArrow}a');
@@ -113,6 +125,14 @@ describe('Keymaps', () => {
113
125
  });
114
126
 
115
127
  describe('selectNextOccurrence', () => {
128
+ beforeEach(() => {
129
+ loadPlayroom(`
130
+ <div>First line</div>
131
+ <div>Second line</div>
132
+ <div>Third line</div>
133
+ `);
134
+ });
135
+
116
136
  const cmdPlusD = cmdPlus('D');
117
137
 
118
138
  it('should select the current word on one use', () => {
@@ -169,6 +189,14 @@ describe('Keymaps', () => {
169
189
  });
170
190
 
171
191
  describe('addCursor', () => {
192
+ beforeEach(() => {
193
+ loadPlayroom(`
194
+ <div>First line</div>
195
+ <div>Second line</div>
196
+ <div>Third line</div>
197
+ `);
198
+ });
199
+
172
200
  it('should add a cursor on the next line', () => {
173
201
  typeCode(`{${cmdPlus('alt+downArrow')}}a`);
174
202
  assertCodePaneContains(dedent`
@@ -190,6 +218,13 @@ describe('Keymaps', () => {
190
218
  });
191
219
 
192
220
  describe('wrapTag', () => {
221
+ beforeEach(() => {
222
+ loadPlayroom(`
223
+ <div>First line</div>
224
+ <div>Second line</div>
225
+ <div>Third line</div>
226
+ `);
227
+ });
193
228
  const modifierKey = isMac() ? 'cmd' : 'ctrl';
194
229
 
195
230
  it("should insert a fragment with cursors when there's no selection", () => {
@@ -216,6 +251,21 @@ describe('Keymaps', () => {
216
251
  `);
217
252
  });
218
253
 
254
+ it('should ignore surrounding whitespace when wrapping a single line selection', () => {
255
+ typeCode(' ');
256
+ typeCode('{leftArrow}');
257
+ selectToEndOfLine();
258
+
259
+ typeCode(`{shift+${modifierKey}+,}`);
260
+ typeCode('span');
261
+
262
+ assertCodePaneContains(dedent`
263
+ <span> <div>First line</div></span>
264
+ <div>Second line</div>
265
+ <div>Third line</div>
266
+ `);
267
+ });
268
+
219
269
  it('should wrap a multi-line selection', () => {
220
270
  typeCode('{shift+downArrow}');
221
271
  selectToEndOfLine();
@@ -280,7 +330,7 @@ describe('Keymaps', () => {
280
330
  typeCode(`{${modifierKey}+alt+downArrow}`);
281
331
  typeCode('{shift+alt+downArrow}{upArrow}');
282
332
 
283
- selectLines(1);
333
+ selectNextLines(1);
284
334
  selectToEndOfLine();
285
335
 
286
336
  typeCode(`{shift+${modifierKey}+,}`);
@@ -299,4 +349,1450 @@ describe('Keymaps', () => {
299
349
  `);
300
350
  });
301
351
  });
352
+
353
+ describe('toggleComment', () => {
354
+ const blockStarter = `
355
+ <div>First line</div>
356
+ <div>Second line</div>
357
+ <div>Third line</div>`;
358
+
359
+ const lineStarter = `
360
+ <div
361
+ prop1="This is the first prop"
362
+ prop2="This is the second prop"
363
+ prop3="This is the third prop"
364
+ >
365
+ First line
366
+ </div>
367
+ <div>Second line</div>
368
+ <div>Third line</div>`;
369
+
370
+ const modifierKey = isMac() ? 'cmd' : 'ctrl';
371
+ const executeToggleCommentCommand = () => typeCode(`{${modifierKey}+/}`);
372
+
373
+ describe('should wrap a single line in a comment when there is no selection', () => {
374
+ it('block', () => {
375
+ loadPlayroom(blockStarter);
376
+ executeToggleCommentCommand();
377
+
378
+ assertCodePaneContains(dedent`
379
+ {/* <div>First line</div> */}
380
+ <div>Second line</div>
381
+ <div>Third line</div>
382
+ `);
383
+ });
384
+
385
+ it('line', () => {
386
+ loadPlayroom(lineStarter);
387
+
388
+ moveBy(0, 1);
389
+
390
+ executeToggleCommentCommand();
391
+
392
+ assertCodePaneContains(dedent`
393
+ <div
394
+ // prop1="This is the first prop"
395
+ prop2="This is the second prop"
396
+ prop3="This is the third prop"
397
+ >
398
+ First line
399
+ </div>
400
+ <div>Second line</div>
401
+ <div>Third line</div>
402
+ `);
403
+ });
404
+
405
+ it('line in callback', () => {
406
+ loadPlayroom(`
407
+ <button
408
+ onClick={() =>
409
+ getState("activeStep") > 1 &&
410
+ setState("activeStep", getState("activeStep") - 1)
411
+ }
412
+ >
413
+ Text
414
+ </button>
415
+ `);
416
+
417
+ moveBy(0, 2);
418
+
419
+ executeToggleCommentCommand();
420
+
421
+ assertCodePaneContains(dedent`
422
+ <button
423
+ onClick={() =>
424
+ // getState("activeStep") > 1 &&
425
+ setState("activeStep", getState("activeStep") - 1)
426
+ }
427
+ >
428
+ Text
429
+ </button>
430
+ `);
431
+ });
432
+ });
433
+
434
+ describe('should wrap a single line selection in a comment', () => {
435
+ describe('standard', () => {
436
+ it('block', () => {
437
+ loadPlayroom(blockStarter);
438
+ selectToEndOfLine();
439
+
440
+ executeToggleCommentCommand();
441
+
442
+ assertCodePaneContains(dedent`
443
+ {/* <div>First line</div> */}
444
+ <div>Second line</div>
445
+ <div>Third line</div>
446
+ `);
447
+ });
448
+
449
+ it('line', () => {
450
+ loadPlayroom(lineStarter);
451
+
452
+ moveBy(0, 1);
453
+ selectToEndOfLine();
454
+
455
+ executeToggleCommentCommand();
456
+
457
+ assertCodePaneContains(dedent`
458
+ <div
459
+ // prop1="This is the first prop"
460
+ prop2="This is the second prop"
461
+ prop3="This is the third prop"
462
+ >
463
+ First line
464
+ </div>
465
+ <div>Second line</div>
466
+ <div>Third line</div>
467
+ `);
468
+ });
469
+ });
470
+
471
+ describe('without shifting selection position for a forward selection', () => {
472
+ it('block', () => {
473
+ loadPlayroom(blockStarter);
474
+ selectToEndOfLine();
475
+
476
+ executeToggleCommentCommand();
477
+
478
+ typeCode(`{shift+leftArrow}`);
479
+ typeCode('c');
480
+
481
+ assertCodePaneContains(dedent`
482
+ {/* c> */}
483
+ <div>Second line</div>
484
+ <div>Third line</div>
485
+ `);
486
+ });
487
+
488
+ it('line', () => {
489
+ loadPlayroom(lineStarter);
490
+
491
+ moveBy(0, 1);
492
+ moveByWords(1);
493
+ selectToEndOfLine();
494
+
495
+ executeToggleCommentCommand();
496
+
497
+ typeCode(`{shift+leftArrow}`);
498
+ typeCode('c');
499
+
500
+ assertCodePaneContains(dedent`
501
+ <div
502
+ // c"
503
+ prop2="This is the second prop"
504
+ prop3="This is the third prop"
505
+ >
506
+ First line
507
+ </div>
508
+ <div>Second line</div>
509
+ <div>Third line</div>
510
+ `);
511
+ });
512
+ });
513
+
514
+ describe('without shifting selection position for a backward selection', () => {
515
+ it('block', () => {
516
+ loadPlayroom(blockStarter);
517
+
518
+ moveToEndOfLine();
519
+ selectToStartOfLine();
520
+
521
+ executeToggleCommentCommand();
522
+
523
+ typeCode(`{shift+rightArrow}`);
524
+ typeCode('c');
525
+
526
+ assertCodePaneContains(dedent`
527
+ {/* <c */}
528
+ <div>Second line</div>
529
+ <div>Third line</div>
530
+ `);
531
+ });
532
+
533
+ it('line', () => {
534
+ loadPlayroom(lineStarter);
535
+
536
+ moveBy(0, 1);
537
+ moveToEndOfLine();
538
+
539
+ // Todo - (1/2) Solve issue where Ubuntu does not select to the start of line
540
+ // Todo - (2/2) with one trigger of the keybinding
541
+ selectToStartOfLine();
542
+ selectToStartOfLine();
543
+
544
+ executeToggleCommentCommand();
545
+
546
+ typeCode(`{shift+rightArrow}`);
547
+ typeCode('c');
548
+
549
+ assertCodePaneContains(dedent`
550
+ <div
551
+ c
552
+ prop2="This is the second prop"
553
+ prop3="This is the third prop"
554
+ >
555
+ First line
556
+ </div>
557
+ <div>Second line</div>
558
+ <div>Third line</div>
559
+ `);
560
+ });
561
+ });
562
+
563
+ describe('when the line is only partially selected', () => {
564
+ it('block', () => {
565
+ loadPlayroom(blockStarter);
566
+
567
+ moveByWords(3);
568
+ selectNextWords(2);
569
+
570
+ executeToggleCommentCommand();
571
+
572
+ assertCodePaneContains(dedent`
573
+ {/* <div>First line</div> */}
574
+ <div>Second line</div>
575
+ <div>Third line</div>
576
+ `);
577
+
578
+ typeCode('c');
579
+
580
+ assertCodePaneContains(dedent`
581
+ {/* <div>c</div> */}
582
+ <div>Second line</div>
583
+ <div>Third line</div>
584
+ `);
585
+ });
586
+
587
+ it('line', () => {
588
+ loadPlayroom(lineStarter);
589
+
590
+ moveBy(0, 1);
591
+ moveByWords(3);
592
+
593
+ selectNextWords(2);
594
+
595
+ executeToggleCommentCommand();
596
+
597
+ assertCodePaneContains(dedent`
598
+ <div
599
+ // prop1="This is the first prop"
600
+ prop2="This is the second prop"
601
+ prop3="This is the third prop"
602
+ >
603
+ First line
604
+ </div>
605
+ <div>Second line</div>
606
+ <div>Third line</div>
607
+ `);
608
+
609
+ typeCode('c');
610
+
611
+ assertCodePaneContains(dedent`
612
+ <div
613
+ // prop1="c the first prop"
614
+ prop2="This is the second prop"
615
+ prop3="This is the third prop"
616
+ >
617
+ First line
618
+ </div>
619
+ <div>Second line</div>
620
+ <div>Third line</div>
621
+ `);
622
+ });
623
+ });
624
+
625
+ describe('and respect indent levels', () => {
626
+ it('block', () => {
627
+ loadPlayroom(`
628
+ <div>
629
+ <div>First line</div>
630
+ <div>Second line</div>
631
+ <div>Third line</div>
632
+ </div>
633
+ `);
634
+
635
+ moveBy(0, 1);
636
+ moveByWords(1);
637
+ selectToEndOfLine();
638
+
639
+ executeToggleCommentCommand();
640
+ typeCode('c');
641
+
642
+ assertCodePaneContains(dedent`
643
+ <div>
644
+ {/* c */}
645
+ <div>Second line</div>
646
+ <div>Third line</div>
647
+ </div>
648
+ `);
649
+ });
650
+
651
+ it('line', () => {
652
+ loadPlayroom(lineStarter);
653
+
654
+ moveBy(0, 1);
655
+ moveByWords(1);
656
+ selectToEndOfLine();
657
+
658
+ executeToggleCommentCommand();
659
+ typeCode('c');
660
+
661
+ assertCodePaneContains(dedent`
662
+ <div
663
+ // c
664
+ prop2="This is the second prop"
665
+ prop3="This is the third prop"
666
+ >
667
+ First line
668
+ </div>
669
+ <div>Second line</div>
670
+ <div>Third line</div>
671
+ `);
672
+ });
673
+ });
674
+ });
675
+
676
+ describe('should wrap a multi line selection in a comment', () => {
677
+ describe('standard', () => {
678
+ it('block', () => {
679
+ loadPlayroom(blockStarter);
680
+
681
+ selectNextLines(3);
682
+
683
+ executeToggleCommentCommand();
684
+
685
+ assertCodePaneContains(dedent`
686
+ {/* <div>First line</div>
687
+ <div>Second line</div>
688
+ <div>Third line</div> */}
689
+ `);
690
+ });
691
+
692
+ it('line', () => {
693
+ loadPlayroom(lineStarter);
694
+
695
+ moveBy(0, 1);
696
+ selectNextLines(3);
697
+
698
+ executeToggleCommentCommand();
699
+
700
+ assertCodePaneContains(dedent`
701
+ <div
702
+ // prop1="This is the first prop"
703
+ // prop2="This is the second prop"
704
+ // prop3="This is the third prop"
705
+ >
706
+ First line
707
+ </div>
708
+ <div>Second line</div>
709
+ <div>Third line</div>
710
+ `);
711
+ });
712
+ });
713
+
714
+ describe('when the lines are only partially selected', () => {
715
+ it('block', () => {
716
+ loadPlayroom(blockStarter);
717
+
718
+ moveByWords(3);
719
+ selectNextLines(1);
720
+
721
+ executeToggleCommentCommand();
722
+
723
+ assertCodePaneContains(dedent`
724
+ {/* <div>First line</div>
725
+ <div>Second line</div> */}
726
+ <div>Third line</div>
727
+ `);
728
+ });
729
+
730
+ it('line', () => {
731
+ loadPlayroom(lineStarter);
732
+
733
+ moveBy(0, 1);
734
+ moveByWords(4);
735
+ selectNextLines(1);
736
+
737
+ executeToggleCommentCommand();
738
+
739
+ assertCodePaneContains(dedent`
740
+ <div
741
+ // prop1="This is the first prop"
742
+ // prop2="This is the second prop"
743
+ prop3="This is the third prop"
744
+ >
745
+ First line
746
+ </div>
747
+ <div>Second line</div>
748
+ <div>Third line</div>
749
+ `);
750
+ });
751
+ });
752
+
753
+ describe('and respect indent levels', () => {
754
+ it('block', () => {
755
+ loadPlayroom(`
756
+ <div>
757
+ <div>First line</div>
758
+ <div>Second line</div>
759
+ <div>Third line</div>
760
+ </div>
761
+ `);
762
+
763
+ moveBy(0, 1);
764
+ moveByWords(4);
765
+ selectNextLines(1);
766
+ selectNextWords(1);
767
+
768
+ executeToggleCommentCommand();
769
+ typeCode('c');
770
+
771
+ assertCodePaneContains(dedent`
772
+ <div>
773
+ {/* <div>c line</div> */}
774
+ <div>Third line</div>
775
+ </div>
776
+ `);
777
+ });
778
+
779
+ it('line', () => {
780
+ loadPlayroom(lineStarter);
781
+
782
+ moveBy(0, 1);
783
+ moveByWords(4);
784
+ selectNextLines(1);
785
+ selectNextWords(1);
786
+
787
+ executeToggleCommentCommand();
788
+ typeCode('c');
789
+
790
+ assertCodePaneContains(dedent`
791
+ <div
792
+ // prop1="Thisc the second prop"
793
+ prop3="This is the third prop"
794
+ >
795
+ First line
796
+ </div>
797
+ <div>Second line</div>
798
+ <div>Third line</div>
799
+ `);
800
+ });
801
+ });
802
+ });
803
+
804
+ describe('should uncomment', () => {
805
+ describe('a single line comment', () => {
806
+ describe('with no selection', () => {
807
+ describe('with the cursor proceeding the comment', () => {
808
+ it('block', () => {
809
+ loadPlayroom(`
810
+ {/* <div>First line</div> */}
811
+ <div>Second line</div>
812
+ <div>Third line</div>
813
+ `);
814
+ executeToggleCommentCommand();
815
+
816
+ assertCodePaneContains(dedent`
817
+ <div>First line</div>
818
+ <div>Second line</div>
819
+ <div>Third line</div>
820
+ `);
821
+ });
822
+
823
+ it('line', () => {
824
+ loadPlayroom(lineStarter);
825
+
826
+ moveBy(0, 1);
827
+ executeToggleCommentCommand();
828
+
829
+ assertCodePaneContains(dedent`
830
+ <div
831
+ // prop1="This is the first prop"
832
+ prop2="This is the second prop"
833
+ prop3="This is the third prop"
834
+ >
835
+ First line
836
+ </div>
837
+ <div>Second line</div>
838
+ <div>Third line</div>
839
+ `);
840
+
841
+ typeCode('c');
842
+
843
+ assertCodePaneContains(dedent`
844
+ <div
845
+ c // prop1="This is the first prop"
846
+ prop2="This is the second prop"
847
+ prop3="This is the third prop"
848
+ >
849
+ First line
850
+ </div>
851
+ <div>Second line</div>
852
+ <div>Third line</div>
853
+ `);
854
+ });
855
+ });
856
+
857
+ describe('with the cursor during the opening comment syntax', () => {
858
+ it('block', () => {
859
+ loadPlayroom(`
860
+ <div>
861
+ {/* <div>First line</div> */}
862
+ <div>Second line</div>
863
+ <div>Third line</div>
864
+ </div>
865
+ `);
866
+
867
+ moveBy(0, 1);
868
+ moveByWords(1);
869
+ moveBy(1);
870
+
871
+ executeToggleCommentCommand();
872
+
873
+ assertCodePaneContains(dedent`
874
+ <div>
875
+ <div>First line</div>
876
+ <div>Second line</div>
877
+ <div>Third line</div>
878
+ </div>
879
+ `);
880
+
881
+ typeCode('c');
882
+
883
+ assertCodePaneContains(dedent`
884
+ <div>
885
+ c<div>First line</div>
886
+ <div>Second line</div>
887
+ <div>Third line</div>
888
+ </div>
889
+ `);
890
+ });
891
+
892
+ it('line', () => {
893
+ loadPlayroom(`
894
+ <div
895
+ // prop1="This is the first prop"
896
+ prop2="This is the second prop"
897
+ prop3="This is the third prop"
898
+ >
899
+ First line
900
+ </div>
901
+ <div>Second line</div>
902
+ <div>Third line</div>
903
+ `);
904
+
905
+ moveBy(0, 1);
906
+ moveByWords(1);
907
+ moveBy(1);
908
+
909
+ executeToggleCommentCommand();
910
+
911
+ assertCodePaneContains(dedent`
912
+ <div
913
+ prop1="This is the first prop"
914
+ prop2="This is the second prop"
915
+ prop3="This is the third prop"
916
+ >
917
+ First line
918
+ </div>
919
+ <div>Second line</div>
920
+ <div>Third line</div>
921
+ `);
922
+
923
+ typeCode('c');
924
+
925
+ assertCodePaneContains(dedent`
926
+ <div
927
+ cprop1="This is the first prop"
928
+ prop2="This is the second prop"
929
+ prop3="This is the third prop"
930
+ >
931
+ First line
932
+ </div>
933
+ <div>Second line</div>
934
+ <div>Third line</div>
935
+ `);
936
+ });
937
+ });
938
+
939
+ describe('with the cursor within the comment', () => {
940
+ it('block', () => {
941
+ loadPlayroom(`
942
+ {/* <div>First line</div> */}
943
+ <div>Second line</div>
944
+ <div>Third line</div>
945
+ `);
946
+
947
+ moveByWords(5);
948
+
949
+ executeToggleCommentCommand();
950
+
951
+ assertCodePaneContains(dedent`
952
+ <div>First line</div>
953
+ <div>Second line</div>
954
+ <div>Third line</div>
955
+ `);
956
+
957
+ typeCode('c');
958
+
959
+ assertCodePaneContains(dedent`
960
+ <div>Firstc line</div>
961
+ <div>Second line</div>
962
+ <div>Third line</div>
963
+ `);
964
+ });
965
+
966
+ it('line', () => {
967
+ loadPlayroom(`
968
+ <div
969
+ // prop1="This is the first prop"
970
+ prop2="This is the second prop"
971
+ prop3="This is the third prop"
972
+ >
973
+ First line
974
+ </div>
975
+ <div>Second line</div>
976
+ <div>Third line</div>
977
+ `);
978
+
979
+ moveBy(0, 1);
980
+ moveByWords(5);
981
+
982
+ executeToggleCommentCommand();
983
+
984
+ assertCodePaneContains(dedent`
985
+ <div
986
+ prop1="This is the first prop"
987
+ prop2="This is the second prop"
988
+ prop3="This is the third prop"
989
+ >
990
+ First line
991
+ </div>
992
+ <div>Second line</div>
993
+ <div>Third line</div>
994
+ `);
995
+
996
+ typeCode('c');
997
+
998
+ assertCodePaneContains(dedent`
999
+ <div
1000
+ prop1="Thisc is the first prop"
1001
+ prop2="This is the second prop"
1002
+ prop3="This is the third prop"
1003
+ >
1004
+ First line
1005
+ </div>
1006
+ <div>Second line</div>
1007
+ <div>Third line</div>
1008
+ `);
1009
+ });
1010
+ });
1011
+ });
1012
+
1013
+ describe('with partial internal selection', () => {
1014
+ it('block', () => {
1015
+ loadPlayroom(`
1016
+ {/* <div>First line</div> */}
1017
+ <div>Second line</div>
1018
+ <div>Third line</div>
1019
+ `);
1020
+
1021
+ moveByWords(4);
1022
+ selectNextWords(2);
1023
+ executeToggleCommentCommand();
1024
+
1025
+ assertCodePaneContains(dedent`
1026
+ <div>First line</div>
1027
+ <div>Second line</div>
1028
+ <div>Third line</div>
1029
+ `);
1030
+
1031
+ typeCode('c');
1032
+
1033
+ assertCodePaneContains(dedent`
1034
+ <div>c</div>
1035
+ <div>Second line</div>
1036
+ <div>Third line</div>
1037
+ `);
1038
+ });
1039
+
1040
+ it('line', () => {
1041
+ loadPlayroom(`
1042
+ <div
1043
+ // prop1="This is the first prop"
1044
+ prop2="This is the second prop"
1045
+ prop3="This is the third prop"
1046
+ >
1047
+ First line
1048
+ </div>
1049
+ <div>Second line</div>
1050
+ <div>Third line</div>
1051
+ `);
1052
+
1053
+ moveBy(0, 1);
1054
+ moveByWords(4);
1055
+ selectNextWords(2);
1056
+ executeToggleCommentCommand();
1057
+
1058
+ assertCodePaneContains(dedent`
1059
+ <div
1060
+ prop1="This is the first prop"
1061
+ prop2="This is the second prop"
1062
+ prop3="This is the third prop"
1063
+ >
1064
+ First line
1065
+ </div>
1066
+ <div>Second line</div>
1067
+ <div>Third line</div>
1068
+ `);
1069
+
1070
+ typeCode('c');
1071
+
1072
+ assertCodePaneContains(dedent`
1073
+ <div
1074
+ prop1="c the first prop"
1075
+ prop2="This is the second prop"
1076
+ prop3="This is the third prop"
1077
+ >
1078
+ First line
1079
+ </div>
1080
+ <div>Second line</div>
1081
+ <div>Third line</div>
1082
+ `);
1083
+ });
1084
+ });
1085
+
1086
+ describe('with full external selection', () => {
1087
+ it('block', () => {
1088
+ loadPlayroom(`
1089
+ {/* <div>First line</div> */}
1090
+ <div>Second line</div>
1091
+ <div>Third line</div>
1092
+ `);
1093
+
1094
+ selectToEndOfLine();
1095
+ executeToggleCommentCommand();
1096
+
1097
+ assertCodePaneContains(dedent`
1098
+ <div>First line</div>
1099
+ <div>Second line</div>
1100
+ <div>Third line</div>
1101
+ `);
1102
+
1103
+ typeCode('c');
1104
+
1105
+ assertCodePaneContains(dedent`
1106
+ c
1107
+ <div>Second line</div>
1108
+ <div>Third line</div>
1109
+ `);
1110
+ });
1111
+
1112
+ it('line', () => {
1113
+ loadPlayroom(`
1114
+ <div
1115
+ // prop1="This is the first prop"
1116
+ prop2="This is the second prop"
1117
+ prop3="This is the third prop"
1118
+ >
1119
+ First line
1120
+ </div>
1121
+ <div>Second line</div>
1122
+ <div>Third line</div>
1123
+ `);
1124
+
1125
+ moveBy(0, 1);
1126
+ selectToEndOfLine();
1127
+ executeToggleCommentCommand();
1128
+
1129
+ assertCodePaneContains(dedent`
1130
+ <div
1131
+ prop1="This is the first prop"
1132
+ prop2="This is the second prop"
1133
+ prop3="This is the third prop"
1134
+ >
1135
+ First line
1136
+ </div>
1137
+ <div>Second line</div>
1138
+ <div>Third line</div>
1139
+ `);
1140
+
1141
+ typeCode('c');
1142
+
1143
+ assertCodePaneContains(dedent`
1144
+ <div
1145
+ c
1146
+ prop2="This is the second prop"
1147
+ prop3="This is the third prop"
1148
+ >
1149
+ First line
1150
+ </div>
1151
+ <div>Second line</div>
1152
+ <div>Third line</div>
1153
+ `);
1154
+ });
1155
+ });
1156
+
1157
+ describe('with an external to internal selection', () => {
1158
+ it('block', () => {
1159
+ loadPlayroom(`
1160
+ {/* <div>First line</div> */}
1161
+ <div>Second line</div>
1162
+ <div>Third line</div>
1163
+ `);
1164
+
1165
+ selectNextWords(5);
1166
+ executeToggleCommentCommand();
1167
+
1168
+ assertCodePaneContains(dedent`
1169
+ <div>First line</div>
1170
+ <div>Second line</div>
1171
+ <div>Third line</div>
1172
+ `);
1173
+
1174
+ typeCode('c');
1175
+
1176
+ assertCodePaneContains(dedent`
1177
+ c line</div>
1178
+ <div>Second line</div>
1179
+ <div>Third line</div>
1180
+ `);
1181
+ });
1182
+
1183
+ it('line', () => {
1184
+ loadPlayroom(`
1185
+ <div
1186
+ // prop1="This is the first prop"
1187
+ prop2="This is the second prop"
1188
+ prop3="This is the third prop"
1189
+ >
1190
+ First line
1191
+ </div>
1192
+ <div>Second line</div>
1193
+ <div>Third line</div>
1194
+ `);
1195
+
1196
+ moveBy(0, 1);
1197
+ selectNextWords(5);
1198
+ executeToggleCommentCommand();
1199
+
1200
+ assertCodePaneContains(dedent`
1201
+ <div
1202
+ prop1="This is the first prop"
1203
+ prop2="This is the second prop"
1204
+ prop3="This is the third prop"
1205
+ >
1206
+ First line
1207
+ </div>
1208
+ <div>Second line</div>
1209
+ <div>Third line</div>
1210
+ `);
1211
+
1212
+ typeCode('c');
1213
+
1214
+ assertCodePaneContains(dedent`
1215
+ <div
1216
+ c is the first prop"
1217
+ prop2="This is the second prop"
1218
+ prop3="This is the third prop"
1219
+ >
1220
+ First line
1221
+ </div>
1222
+ <div>Second line</div>
1223
+ <div>Third line</div>
1224
+ `);
1225
+ });
1226
+ });
1227
+
1228
+ describe('should respect indentation', () => {
1229
+ describe('for an external, partial selection', () => {
1230
+ it('block', () => {
1231
+ loadPlayroom(`
1232
+ <div>
1233
+ {/* <div>First line</div> */}
1234
+ <div>Second line</div>
1235
+ <div>Third line</div>
1236
+ </div>
1237
+ `);
1238
+
1239
+ moveBy(0, 1);
1240
+ moveByWords(1);
1241
+ selectNextWords(4);
1242
+
1243
+ executeToggleCommentCommand();
1244
+
1245
+ assertCodePaneContains(dedent`
1246
+ <div>
1247
+ <div>First line</div>
1248
+ <div>Second line</div>
1249
+ <div>Third line</div>
1250
+ </div>
1251
+ `);
1252
+
1253
+ typeCode('c');
1254
+
1255
+ assertCodePaneContains(dedent`
1256
+ <div>
1257
+ cFirst line</div>
1258
+ <div>Second line</div>
1259
+ <div>Third line</div>
1260
+ </div>
1261
+ `);
1262
+ });
1263
+
1264
+ it('line', () => {
1265
+ loadPlayroom(`
1266
+ <div
1267
+ // prop1="This is the first prop"
1268
+ prop2="This is the second prop"
1269
+ prop3="This is the third prop"
1270
+ >
1271
+ First line
1272
+ </div>
1273
+ <div>Second line</div>
1274
+ <div>Third line</div>
1275
+ `);
1276
+
1277
+ moveBy(0, 1);
1278
+ moveByWords(1);
1279
+
1280
+ selectNextWords(3);
1281
+
1282
+ executeToggleCommentCommand();
1283
+
1284
+ assertCodePaneContains(dedent`
1285
+ <div
1286
+ prop1="This is the first prop"
1287
+ prop2="This is the second prop"
1288
+ prop3="This is the third prop"
1289
+ >
1290
+ First line
1291
+ </div>
1292
+ <div>Second line</div>
1293
+ <div>Third line</div>
1294
+ `);
1295
+
1296
+ typeCode('c');
1297
+
1298
+ assertCodePaneContains(dedent`
1299
+ <div
1300
+ cThis is the first prop"
1301
+ prop2="This is the second prop"
1302
+ prop3="This is the third prop"
1303
+ >
1304
+ First line
1305
+ </div>
1306
+ <div>Second line</div>
1307
+ <div>Third line</div>
1308
+ `);
1309
+ });
1310
+ });
1311
+
1312
+ describe('for an internal, partial selection', () => {
1313
+ it('block', () => {
1314
+ loadPlayroom(`
1315
+ <div>
1316
+ {/* <div>First line</div> */}
1317
+ <div>Second line</div>
1318
+ <div>Third line</div>
1319
+ </div>
1320
+ `);
1321
+
1322
+ moveBy(0, 1);
1323
+ moveByWords(5);
1324
+ selectNextWords(2);
1325
+
1326
+ executeToggleCommentCommand();
1327
+
1328
+ assertCodePaneContains(dedent`
1329
+ <div>
1330
+ <div>First line</div>
1331
+ <div>Second line</div>
1332
+ <div>Third line</div>
1333
+ </div>
1334
+ `);
1335
+
1336
+ typeCode('c');
1337
+
1338
+ assertCodePaneContains(dedent`
1339
+ <div>
1340
+ <div>c</div>
1341
+ <div>Second line</div>
1342
+ <div>Third line</div>
1343
+ </div>
1344
+ `);
1345
+ });
1346
+
1347
+ it('line', () => {
1348
+ loadPlayroom(`
1349
+ <div
1350
+ // prop1="This is the first prop"
1351
+ prop2="This is the second prop"
1352
+ prop3="This is the third prop"
1353
+ >
1354
+ First line
1355
+ </div>
1356
+ <div>Second line</div>
1357
+ <div>Third line</div>
1358
+ `);
1359
+
1360
+ moveBy(0, 1);
1361
+ moveByWords(4);
1362
+ selectNextWords(5);
1363
+
1364
+ executeToggleCommentCommand();
1365
+
1366
+ assertCodePaneContains(dedent`
1367
+ <div
1368
+ prop1="This is the first prop"
1369
+ prop2="This is the second prop"
1370
+ prop3="This is the third prop"
1371
+ >
1372
+ First line
1373
+ </div>
1374
+ <div>Second line</div>
1375
+ <div>Third line</div>
1376
+ `);
1377
+
1378
+ typeCode('c');
1379
+
1380
+ assertCodePaneContains(dedent`
1381
+ <div
1382
+ prop1="c"
1383
+ prop2="This is the second prop"
1384
+ prop3="This is the third prop"
1385
+ >
1386
+ First line
1387
+ </div>
1388
+ <div>Second line</div>
1389
+ <div>Third line</div>
1390
+ `);
1391
+ });
1392
+ });
1393
+
1394
+ describe('for an selection beginning during opening comment syntax', () => {
1395
+ it('block', () => {
1396
+ loadPlayroom(`
1397
+ <div>
1398
+ {/* <div>First line</div> */}
1399
+ <div>Second line</div>
1400
+ <div>Third line</div>
1401
+ </div>
1402
+ `);
1403
+
1404
+ moveBy(0, 1);
1405
+ moveByWords(1);
1406
+ moveBy(1);
1407
+ selectNextWords(4);
1408
+
1409
+ executeToggleCommentCommand();
1410
+
1411
+ assertCodePaneContains(dedent`
1412
+ <div>
1413
+ <div>First line</div>
1414
+ <div>Second line</div>
1415
+ <div>Third line</div>
1416
+ </div>
1417
+ `);
1418
+
1419
+ typeCode('c');
1420
+
1421
+ assertCodePaneContains(dedent`
1422
+ <div>
1423
+ cFirst line</div>
1424
+ <div>Second line</div>
1425
+ <div>Third line</div>
1426
+ </div>
1427
+ `);
1428
+ });
1429
+
1430
+ it('line', () => {
1431
+ loadPlayroom(`
1432
+ <div
1433
+ // prop1="This is the first prop"
1434
+ prop2="This is the second prop"
1435
+ prop3="This is the third prop"
1436
+ >
1437
+ First line
1438
+ </div>
1439
+ <div>Second line</div>
1440
+ <div>Third line</div>
1441
+ `);
1442
+
1443
+ moveBy(0, 1);
1444
+ moveByWords(1);
1445
+ moveBy(1);
1446
+ selectNextWords(3);
1447
+
1448
+ executeToggleCommentCommand();
1449
+
1450
+ assertCodePaneContains(dedent`
1451
+ <div
1452
+ prop1="This is the first prop"
1453
+ prop2="This is the second prop"
1454
+ prop3="This is the third prop"
1455
+ >
1456
+ First line
1457
+ </div>
1458
+ <div>Second line</div>
1459
+ <div>Third line</div>
1460
+ `);
1461
+
1462
+ typeCode('c');
1463
+
1464
+ assertCodePaneContains(dedent`
1465
+ <div
1466
+ cThis is the first prop"
1467
+ prop2="This is the second prop"
1468
+ prop3="This is the third prop"
1469
+ >
1470
+ First line
1471
+ </div>
1472
+ <div>Second line</div>
1473
+ <div>Third line</div>
1474
+ `);
1475
+ });
1476
+ });
1477
+
1478
+ describe('for no selection', () => {
1479
+ it('block', () => {
1480
+ loadPlayroom(`
1481
+ <div>
1482
+ {/* <div>First line</div> */}
1483
+ <div>Second line</div>
1484
+ <div>Third line</div>
1485
+ </div>
1486
+ `);
1487
+
1488
+ moveBy(0, 1);
1489
+ moveByWords(1);
1490
+
1491
+ executeToggleCommentCommand();
1492
+
1493
+ assertCodePaneContains(dedent`
1494
+ <div>
1495
+ <div>First line</div>
1496
+ <div>Second line</div>
1497
+ <div>Third line</div>
1498
+ </div>
1499
+ `);
1500
+
1501
+ typeCode('c');
1502
+
1503
+ assertCodePaneContains(dedent`
1504
+ <div>
1505
+ c<div>First line</div>
1506
+ <div>Second line</div>
1507
+ <div>Third line</div>
1508
+ </div>
1509
+ `);
1510
+ });
1511
+
1512
+ it('line', () => {
1513
+ loadPlayroom(`
1514
+ <div
1515
+ // prop1="This is the first prop"
1516
+ prop2="This is the second prop"
1517
+ prop3="This is the third prop"
1518
+ >
1519
+ First line
1520
+ </div>
1521
+ <div>Second line</div>
1522
+ <div>Third line</div>
1523
+ `);
1524
+
1525
+ moveBy(0, 1);
1526
+ moveByWords(1);
1527
+
1528
+ executeToggleCommentCommand();
1529
+
1530
+ assertCodePaneContains(dedent`
1531
+ <div
1532
+ prop1="This is the first prop"
1533
+ prop2="This is the second prop"
1534
+ prop3="This is the third prop"
1535
+ >
1536
+ First line
1537
+ </div>
1538
+ <div>Second line</div>
1539
+ <div>Third line</div>
1540
+ `);
1541
+
1542
+ typeCode('c');
1543
+
1544
+ assertCodePaneContains(dedent`
1545
+ <div
1546
+ cprop1="This is the first prop"
1547
+ prop2="This is the second prop"
1548
+ prop3="This is the third prop"
1549
+ >
1550
+ First line
1551
+ </div>
1552
+ <div>Second line</div>
1553
+ <div>Third line</div>
1554
+ `);
1555
+ });
1556
+ });
1557
+ });
1558
+
1559
+ describe('should preserve secondary comments at the end of the line', () => {
1560
+ it('line', () => {
1561
+ loadPlayroom(`
1562
+ <div
1563
+ prop1="This is the first prop" // Prop1
1564
+ prop2="This is the second prop"
1565
+ prop3="This is the third prop"
1566
+ >
1567
+ First line
1568
+ </div>
1569
+ <div>Second line</div>
1570
+ <div>Third line</div>
1571
+ `);
1572
+
1573
+ moveBy(0, 1);
1574
+
1575
+ executeToggleCommentCommand();
1576
+
1577
+ assertCodePaneContains(dedent`
1578
+ <div
1579
+ // prop1="This is the first prop" // Prop1
1580
+ prop2="This is the second prop"
1581
+ prop3="This is the third prop"
1582
+ >
1583
+ First line
1584
+ </div>
1585
+ <div>Second line</div>
1586
+ <div>Third line</div>
1587
+ `);
1588
+
1589
+ executeToggleCommentCommand();
1590
+
1591
+ assertCodePaneContains(dedent`
1592
+ <div
1593
+ prop1="This is the first prop" // Prop1
1594
+ prop2="This is the second prop"
1595
+ prop3="This is the third prop"
1596
+ >
1597
+ First line
1598
+ </div>
1599
+ <div>Second line</div>
1600
+ <div>Third line</div>
1601
+ `);
1602
+ });
1603
+ });
1604
+ });
1605
+
1606
+ describe('a multi line comment', () => {
1607
+ describe('with partial internal selection that spans all lines of the comment', () => {
1608
+ it('block', () => {
1609
+ loadPlayroom(`
1610
+ {/* <div>First line</div>
1611
+ <div>Second line</div>
1612
+ <div>Third line</div> */}
1613
+ `);
1614
+
1615
+ moveByWords(4);
1616
+ selectNextLines(2);
1617
+ executeToggleCommentCommand();
1618
+
1619
+ assertCodePaneContains(dedent`
1620
+ <div>First line</div>
1621
+ <div>Second line</div>
1622
+ <div>Third line</div>
1623
+ `);
1624
+
1625
+ typeCode('c');
1626
+
1627
+ assertCodePaneContains(dedent`
1628
+ <div>cd line</div>
1629
+ `);
1630
+ });
1631
+
1632
+ it('line', () => {
1633
+ loadPlayroom(`
1634
+ <div
1635
+ // prop1="This is the first prop"
1636
+ // prop2="This is the second prop"
1637
+ // prop3="This is the third prop"
1638
+ >
1639
+ First line
1640
+ </div>
1641
+ <div>Second line</div>
1642
+ <div>Third line</div>
1643
+ `);
1644
+
1645
+ moveBy(0, 1);
1646
+ moveByWords(4);
1647
+ selectNextLines(2);
1648
+ executeToggleCommentCommand();
1649
+
1650
+ assertCodePaneContains(dedent`
1651
+ <div
1652
+ prop1="This is the first prop"
1653
+ prop2="This is the second prop"
1654
+ prop3="This is the third prop"
1655
+ >
1656
+ First line
1657
+ </div>
1658
+ <div>Second line</div>
1659
+ <div>Third line</div>
1660
+ `);
1661
+
1662
+ typeCode('c');
1663
+
1664
+ assertCodePaneContains(dedent`
1665
+ <div
1666
+ prop1="cThis is the third prop"
1667
+ >
1668
+ First line
1669
+ </div>
1670
+ <div>Second line</div>
1671
+ <div>Third line</div>
1672
+ `);
1673
+ });
1674
+ });
1675
+
1676
+ describe('with full external selection that spans all lines of the comment', () => {
1677
+ it('block', () => {
1678
+ loadPlayroom(`
1679
+ {/* <div>First line</div>
1680
+ <div>Second line</div>
1681
+ <div>Third line</div> */}
1682
+ `);
1683
+
1684
+ selectNextLines(3);
1685
+ executeToggleCommentCommand();
1686
+
1687
+ assertCodePaneContains(dedent`
1688
+ <div>First line</div>
1689
+ <div>Second line</div>
1690
+ <div>Third line</div>
1691
+ `);
1692
+ });
1693
+
1694
+ it('line', () => {
1695
+ loadPlayroom(`
1696
+ <div
1697
+ // prop1="This is the first prop"
1698
+ // prop2="This is the second prop"
1699
+ // prop3="This is the third prop"
1700
+ >
1701
+ First line
1702
+ </div>
1703
+ <div>Second line</div>
1704
+ <div>Third line</div>
1705
+ `);
1706
+
1707
+ moveBy(0, 1);
1708
+ selectNextLines(3);
1709
+ executeToggleCommentCommand();
1710
+
1711
+ assertCodePaneContains(dedent`
1712
+ <div
1713
+ prop1="This is the first prop"
1714
+ prop2="This is the second prop"
1715
+ prop3="This is the third prop"
1716
+ >
1717
+ First line
1718
+ </div>
1719
+ <div>Second line</div>
1720
+ <div>Third line</div>
1721
+ `);
1722
+ });
1723
+ });
1724
+
1725
+ describe('with an external to internal selection that spans all lines of the comment', () => {
1726
+ it('block', () => {
1727
+ loadPlayroom(`
1728
+ {/* <div>First line</div>
1729
+ <div>Second line</div>
1730
+ <div>Third line</div> */}
1731
+ `);
1732
+
1733
+ selectNextWords(5);
1734
+ selectNextLines(2);
1735
+
1736
+ executeToggleCommentCommand();
1737
+
1738
+ assertCodePaneContains(dedent`
1739
+ <div>First line</div>
1740
+ <div>Second line</div>
1741
+ <div>Third line</div>
1742
+ `);
1743
+
1744
+ typeCode('c');
1745
+
1746
+ assertCodePaneContains(dedent`
1747
+ ce</div>
1748
+ `);
1749
+ });
1750
+
1751
+ it('line', () => {
1752
+ loadPlayroom(`
1753
+ <div
1754
+ // prop1="This is the first prop"
1755
+ // prop2="This is the second prop"
1756
+ // prop3="This is the third prop"
1757
+ >
1758
+ First line
1759
+ </div>
1760
+ <div>Second line</div>
1761
+ <div>Third line</div>
1762
+ `);
1763
+
1764
+ moveBy(0, 1);
1765
+ selectNextWords(5);
1766
+ selectNextLines(2);
1767
+
1768
+ executeToggleCommentCommand();
1769
+
1770
+ assertCodePaneContains(dedent`
1771
+ <div
1772
+ prop1="This is the first prop"
1773
+ prop2="This is the second prop"
1774
+ prop3="This is the third prop"
1775
+ >
1776
+ First line
1777
+ </div>
1778
+ <div>Second line</div>
1779
+ <div>Third line</div>
1780
+ `);
1781
+
1782
+ typeCode('c');
1783
+
1784
+ assertCodePaneContains(dedent`
1785
+ <div
1786
+ c is the third prop"
1787
+ >
1788
+ First line
1789
+ </div>
1790
+ <div>Second line</div>
1791
+ <div>Third line</div>
1792
+ `);
1793
+ });
1794
+ });
1795
+ });
1796
+ });
1797
+ });
302
1798
  });