@@ -567,6 +567,142 @@ function isWarned(emitter) {
567
567
assert . strictEqual ( cursorPos . cols , expectedLines . slice ( - 1 ) [ 0 ] . length ) ;
568
568
rli . close ( ) ;
569
569
}
570
+
571
+ {
572
+ // Beginning and end of line
573
+ const fi = new FakeInput ( ) ;
574
+ const rli = new readline . Interface ( {
575
+ input : fi ,
576
+ output : fi ,
577
+ prompt : '' ,
578
+ terminal : terminal
579
+ } ) ;
580
+ fi . emit ( 'data' , 'the quick brown fox' ) ;
581
+ fi . emit ( 'keypress' , '.' , { ctrl : true , name : 'a' } ) ;
582
+ let cursorPos = rli . _getCursorPos ( ) ;
583
+ assert . strictEqual ( cursorPos . rows , 0 ) ;
584
+ assert . strictEqual ( cursorPos . cols , 0 ) ;
585
+ fi . emit ( 'keypress' , '.' , { ctrl : true , name : 'e' } ) ;
586
+ cursorPos = rli . _getCursorPos ( ) ;
587
+ assert . strictEqual ( cursorPos . rows , 0 ) ;
588
+ assert . strictEqual ( cursorPos . cols , 19 ) ;
589
+ rli . close ( ) ;
590
+ }
591
+
592
+ {
593
+ // `wordLeft` and `wordRight`
594
+ const fi = new FakeInput ( ) ;
595
+ const rli = new readline . Interface ( {
596
+ input : fi ,
597
+ output : fi ,
598
+ prompt : '' ,
599
+ terminal : terminal
600
+ } ) ;
601
+ fi . emit ( 'data' , 'the quick brown fox' ) ;
602
+ fi . emit ( 'keypress' , '.' , { ctrl : true , name : 'left' } ) ;
603
+ let cursorPos = rli . _getCursorPos ( ) ;
604
+ assert . strictEqual ( cursorPos . rows , 0 ) ;
605
+ assert . strictEqual ( cursorPos . cols , 16 ) ;
606
+ fi . emit ( 'keypress' , '.' , { meta : true , name : 'b' } ) ;
607
+ cursorPos = rli . _getCursorPos ( ) ;
608
+ assert . strictEqual ( cursorPos . rows , 0 ) ;
609
+ assert . strictEqual ( cursorPos . cols , 10 ) ;
610
+ fi . emit ( 'keypress' , '.' , { ctrl : true , name : 'right' } ) ;
611
+ cursorPos = rli . _getCursorPos ( ) ;
612
+ assert . strictEqual ( cursorPos . rows , 0 ) ;
613
+ assert . strictEqual ( cursorPos . cols , 16 ) ;
614
+ fi . emit ( 'keypress' , '.' , { meta : true , name : 'f' } ) ;
615
+ cursorPos = rli . _getCursorPos ( ) ;
616
+ assert . strictEqual ( cursorPos . rows , 0 ) ;
617
+ assert . strictEqual ( cursorPos . cols , 19 ) ;
618
+ rli . close ( ) ;
619
+ }
620
+
621
+ {
622
+ // `deleteWordLeft`
623
+ [
624
+ { ctrl : true , name : 'w' } ,
625
+ { ctrl : true , name : 'backspace' } ,
626
+ { meta : true , name : 'backspace' }
627
+ ]
628
+ . forEach ( ( deleteWordLeftKey ) => {
629
+ let fi = new FakeInput ( ) ;
630
+ let rli = new readline . Interface ( {
631
+ input : fi ,
632
+ output : fi ,
633
+ prompt : '' ,
634
+ terminal : terminal
635
+ } ) ;
636
+ fi . emit ( 'data' , 'the quick brown fox' ) ;
637
+ fi . emit ( 'keypress' , '.' , { ctrl : true , name : 'left' } ) ;
638
+ rli . on ( 'line' , common . mustCall ( ( line ) => {
639
+ assert . strictEqual ( line , 'the quick fox' ) ;
640
+ } ) ) ;
641
+ fi . emit ( 'keypress' , '.' , deleteWordLeftKey ) ;
642
+ fi . emit ( 'data' , '\n' ) ;
643
+ rli . close ( ) ;
644
+
645
+ // No effect if pressed at beginning of line
646
+ fi = new FakeInput ( ) ;
647
+ rli = new readline . Interface ( {
648
+ input : fi ,
649
+ output : fi ,
650
+ prompt : '' ,
651
+ terminal : terminal
652
+ } ) ;
653
+ fi . emit ( 'data' , 'the quick brown fox' ) ;
654
+ fi . emit ( 'keypress' , '.' , { ctrl : true , name : 'a' } ) ;
655
+ rli . on ( 'line' , common . mustCall ( ( line ) => {
656
+ assert . strictEqual ( line , 'the quick brown fox' ) ;
657
+ } ) ) ;
658
+ fi . emit ( 'keypress' , '.' , deleteWordLeftKey ) ;
659
+ fi . emit ( 'data' , '\n' ) ;
660
+ rli . close ( ) ;
661
+ } ) ;
662
+ }
663
+
664
+ {
665
+ // `deleteWordRight`
666
+ [
667
+ { ctrl : true , name : 'delete' } ,
668
+ { meta : true , name : 'delete' } ,
669
+ { meta : true , name : 'd' }
670
+ ]
671
+ . forEach ( ( deleteWordRightKey ) => {
672
+ let fi = new FakeInput ( ) ;
673
+ let rli = new readline . Interface ( {
674
+ input : fi ,
675
+ output : fi ,
676
+ prompt : '' ,
677
+ terminal : terminal
678
+ } ) ;
679
+ fi . emit ( 'data' , 'the quick brown fox' ) ;
680
+ fi . emit ( 'keypress' , '.' , { ctrl : true , name : 'left' } ) ;
681
+ fi . emit ( 'keypress' , '.' , { ctrl : true , name : 'left' } ) ;
682
+ rli . on ( 'line' , common . mustCall ( ( line ) => {
683
+ assert . strictEqual ( line , 'the quick fox' ) ;
684
+ } ) ) ;
685
+ fi . emit ( 'keypress' , '.' , deleteWordRightKey ) ;
686
+ fi . emit ( 'data' , '\n' ) ;
687
+ rli . close ( ) ;
688
+
689
+ // No effect if pressed at end of line
690
+ fi = new FakeInput ( ) ;
691
+ rli = new readline . Interface ( {
692
+ input : fi ,
693
+ output : fi ,
694
+ prompt : '' ,
695
+ terminal : terminal
696
+ } ) ;
697
+ fi . emit ( 'data' , 'the quick brown fox' ) ;
698
+ rli . on ( 'line' , common . mustCall ( ( line ) => {
699
+ assert . strictEqual ( line , 'the quick brown fox' ) ;
700
+ } ) ) ;
701
+ fi . emit ( 'keypress' , '.' , deleteWordRightKey ) ;
702
+ fi . emit ( 'data' , '\n' ) ;
703
+ rli . close ( ) ;
704
+ } ) ;
705
+ }
570
706
}
571
707
572
708
// isFullWidthCodePoint() should return false for non-numeric values
0 commit comments