@@ -516,17 +516,19 @@ define(function (require, exports, module) {
516516 myEditor . setCursorPos ( 0 , 0 ) ;
517517
518518 twCommandManager . execute ( Commands . CMD_FIND ) ;
519+ // The previous search term "b" was pre-filled, so the editor was centered there already
520+ expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 1 ) ;
519521
520522 enterSearchText ( "foo" ) ;
521523 expectHighlightedMatches ( fooExpectedMatches ) ;
522524 expectSelection ( fooExpectedMatches [ 0 ] ) ;
523525 expectMatchIndex ( 0 , 4 ) ;
524- expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 1 ) ;
526+ expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 2 ) ;
525527
526528 twCommandManager . execute ( Commands . CMD_FIND_NEXT ) ;
527529 expectSelection ( fooExpectedMatches [ 1 ] ) ;
528530 expectMatchIndex ( 1 , 4 ) ;
529- expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 2 ) ;
531+ expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 3 ) ;
530532 twCommandManager . execute ( Commands . CMD_FIND_NEXT ) ;
531533 expectSelection ( fooExpectedMatches [ 2 ] ) ;
532534 expectMatchIndex ( 2 , 4 ) ;
@@ -539,24 +541,26 @@ define(function (require, exports, module) {
539541 twCommandManager . execute ( Commands . CMD_FIND_NEXT ) ;
540542 expectSelection ( fooExpectedMatches [ 0 ] ) ;
541543 expectMatchIndex ( 0 , 4 ) ;
542- expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 5 ) ;
544+ expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 6 ) ;
543545 } ) ;
544546
545547 it ( "should find all case-insensitive matches with mixed-case text" , function ( ) {
546548 myEditor . setCursorPos ( 0 , 0 ) ;
547549
548550 twCommandManager . execute ( Commands . CMD_FIND ) ;
551+ // The previous search term "foo" was pre-filled, so the editor was centered there already
552+ expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 1 ) ;
549553
550554 enterSearchText ( "Foo" ) ;
551555 expectHighlightedMatches ( fooExpectedMatches ) ;
552556 expectSelection ( fooExpectedMatches [ 0 ] ) ;
553557 expectMatchIndex ( 0 , 4 ) ;
554- expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 1 ) ;
558+ expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 2 ) ;
555559
556560 twCommandManager . execute ( Commands . CMD_FIND_NEXT ) ;
557561 expectSelection ( fooExpectedMatches [ 1 ] ) ;
558562 expectMatchIndex ( 1 , 4 ) ;
559- expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 2 ) ;
563+ expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 3 ) ;
560564 twCommandManager . execute ( Commands . CMD_FIND_NEXT ) ;
561565 expectSelection ( fooExpectedMatches [ 2 ] ) ;
562566 expectMatchIndex ( 2 , 4 ) ;
@@ -569,7 +573,7 @@ define(function (require, exports, module) {
569573 twCommandManager . execute ( Commands . CMD_FIND_NEXT ) ;
570574 expectSelection ( fooExpectedMatches [ 0 ] ) ;
571575 expectMatchIndex ( 0 , 4 ) ;
572- expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 5 ) ;
576+ expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 6 ) ;
573577 } ) ;
574578
575579 it ( "should find all case-sensitive matches with mixed-case text" , function ( ) {
@@ -637,6 +641,8 @@ define(function (require, exports, module) {
637641 myEditor . setCursorPos ( 0 , 0 ) ;
638642
639643 twCommandManager . execute ( Commands . CMD_FIND ) ;
644+ // The previous search term "Foo" was pre-filled, so the editor was centered there already
645+ expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 1 ) ;
640646
641647 enterSearchText ( "foo" ) ;
642648 pressEscape ( ) ;
@@ -647,12 +653,12 @@ define(function (require, exports, module) {
647653
648654 runs ( function ( ) {
649655 expectSelection ( { start : { line : LINE_FIRST_REQUIRE , ch : 8 } , end : { line : LINE_FIRST_REQUIRE , ch : 11 } } ) ;
650- expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 1 ) ;
656+ expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 2 ) ;
651657
652658 // Simple linear Find Next
653659 twCommandManager . execute ( Commands . CMD_FIND_NEXT ) ;
654660 expectSelection ( { start : { line : LINE_FIRST_REQUIRE , ch : 31 } , end : { line : LINE_FIRST_REQUIRE , ch : 34 } } ) ;
655- expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 2 ) ;
661+ expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 3 ) ;
656662 twCommandManager . execute ( Commands . CMD_FIND_NEXT ) ;
657663 expectSelection ( { start : { line : 6 , ch : 17 } , end : { line : 6 , ch : 20 } } ) ;
658664 twCommandManager . execute ( Commands . CMD_FIND_NEXT ) ;
@@ -745,13 +751,13 @@ define(function (require, exports, module) {
745751 } ) ;
746752 } ) ;
747753
748- it ( "shouldn't Find Next after search bar reopened " , function ( ) {
754+ it ( "should remember the last search query " , function ( ) {
749755 runs ( function ( ) {
750756 myEditor . setCursorPos ( 0 , 0 ) ;
751757
752758 twCommandManager . execute ( Commands . CMD_FIND ) ;
753759
754- enterSearchText ( "foo " ) ;
760+ enterSearchText ( "Foo " ) ;
755761 pressEscape ( ) ;
756762 } ) ;
757763
@@ -763,20 +769,36 @@ define(function (require, exports, module) {
763769 twCommandManager . execute ( Commands . CMD_FIND ) ;
764770
765771 expectSearchBarOpen ( ) ;
766- expect ( myEditor ) . toHaveCursorPosition ( 0 , 0 ) ;
772+ expect ( getSearchField ( ) . val ( ) ) . toEqual ( "Foo" ) ;
773+ expectHighlightedMatches ( capitalFooSelections ) ;
774+ expectSelection ( capitalFooSelections [ 0 ] ) ;
775+ expectMatchIndex ( 0 , 3 ) ;
776+ expect ( myEditor . centerOnCursor . calls . length ) . toEqual ( 3 ) ;
767777
768778 twCommandManager . execute ( Commands . CMD_FIND_NEXT ) ;
769- expect ( myEditor ) . toHaveCursorPosition ( 0 , 0 ) ;
779+ expectSelection ( capitalFooSelections [ 1 ] ) ;
780+ expectMatchIndex ( 1 , 3 ) ;
770781 } ) ;
771782 } ) ;
772783
773784 it ( "should open search bar on Find Next with no previous search" , function ( ) {
774- myEditor . setCursorPos ( 0 , 0 ) ;
785+ runs ( function ( ) {
786+ // Make sure we have no previous query
787+ twCommandManager . execute ( Commands . CMD_FIND ) ;
788+ enterSearchText ( "" ) ;
789+ pressEscape ( ) ;
790+ } ) ;
775791
776- twCommandManager . execute ( Commands . CMD_FIND_NEXT ) ;
792+ waitsForSearchBarClose ( ) ;
777793
778- expectSearchBarOpen ( ) ;
779- expect ( myEditor ) . toHaveCursorPosition ( 0 , 0 ) ;
794+ runs ( function ( ) {
795+ myEditor . setCursorPos ( 0 , 0 ) ;
796+
797+ twCommandManager . execute ( Commands . CMD_FIND_NEXT ) ;
798+
799+ expectSearchBarOpen ( ) ;
800+ expect ( myEditor ) . toHaveCursorPosition ( 0 , 0 ) ;
801+ } ) ;
780802 } ) ;
781803
782804 it ( "should select-all without affecting search state if Find invoked while search bar open" , function ( ) { // #2478
@@ -855,16 +877,38 @@ define(function (require, exports, module) {
855877 } ) ;
856878
857879 it ( "should use empty initial query for single cursor selection" , function ( ) {
858- myEditor . setSelection ( { line : LINE_FIRST_REQUIRE , ch : CH_REQUIRE_START } ) ;
859- twCommandManager . execute ( Commands . CMD_FIND ) ;
860- expect ( getSearchField ( ) . val ( ) ) . toEqual ( "" ) ;
880+ runs ( function ( ) {
881+ // Make sure we have no previous query
882+ twCommandManager . execute ( Commands . CMD_FIND ) ;
883+ enterSearchText ( "" ) ;
884+ pressEscape ( ) ;
885+ } ) ;
886+
887+ waitsForSearchBarClose ( ) ;
888+
889+ runs ( function ( ) {
890+ myEditor . setSelection ( { line : LINE_FIRST_REQUIRE , ch : CH_REQUIRE_START } ) ;
891+ twCommandManager . execute ( Commands . CMD_FIND ) ;
892+ expect ( getSearchField ( ) . val ( ) ) . toEqual ( "" ) ;
893+ } ) ;
861894 } ) ;
862895
863896 it ( "should use empty initial query for multiple cursor selection" , function ( ) {
864- myEditor . setSelections ( [ { start : { line : LINE_FIRST_REQUIRE , ch : CH_REQUIRE_START } , end : { line : LINE_FIRST_REQUIRE , ch : CH_REQUIRE_START } , primary : true } ,
865- { start : { line : 1 , ch : 0 } , end : { line : 1 , ch : 0 } } ] ) ;
866- twCommandManager . execute ( Commands . CMD_FIND ) ;
867- expect ( getSearchField ( ) . val ( ) ) . toEqual ( "" ) ;
897+ runs ( function ( ) {
898+ // Make sure we have no previous query
899+ twCommandManager . execute ( Commands . CMD_FIND ) ;
900+ enterSearchText ( "" ) ;
901+ pressEscape ( ) ;
902+ } ) ;
903+
904+ waitsForSearchBarClose ( ) ;
905+
906+ runs ( function ( ) {
907+ myEditor . setSelections ( [ { start : { line : LINE_FIRST_REQUIRE , ch : CH_REQUIRE_START } , end : { line : LINE_FIRST_REQUIRE , ch : CH_REQUIRE_START } , primary : true } ,
908+ { start : { line : 1 , ch : 0 } , end : { line : 1 , ch : 0 } } ] ) ;
909+ twCommandManager . execute ( Commands . CMD_FIND ) ;
910+ expect ( getSearchField ( ) . val ( ) ) . toEqual ( "" ) ;
911+ } ) ;
868912 } ) ;
869913
870914 it ( "should get single selection as initial query" , function ( ) {
@@ -957,6 +1001,15 @@ define(function (require, exports, module) {
9571001
9581002 describe ( "Terminating search" , function ( ) {
9591003 it ( "shouldn't change selection on Escape after typing text, no Find Nexts" , function ( ) {
1004+ runs ( function ( ) {
1005+ // Make sure we have no previous query
1006+ twCommandManager . execute ( Commands . CMD_FIND ) ;
1007+ enterSearchText ( "" ) ;
1008+ pressEscape ( ) ;
1009+ } ) ;
1010+
1011+ waitsForSearchBarClose ( ) ;
1012+
9601013 runs ( function ( ) {
9611014 myEditor . setCursorPos ( LINE_FIRST_REQUIRE , 0 ) ;
9621015
@@ -981,9 +1034,6 @@ define(function (require, exports, module) {
9811034 myEditor . setCursorPos ( LINE_FIRST_REQUIRE , 0 ) ;
9821035
9831036 twCommandManager . execute ( Commands . CMD_FIND ) ;
984- expect ( myEditor ) . toHaveCursorPosition ( LINE_FIRST_REQUIRE , 0 ) ;
985-
986- enterSearchText ( "require" ) ;
9871037 expectSelection ( { start : { line : LINE_FIRST_REQUIRE , ch : CH_REQUIRE_START } , end : { line : LINE_FIRST_REQUIRE , ch : CH_REQUIRE_PAREN } } ) ;
9881038
9891039 twCommandManager . execute ( Commands . CMD_FIND_NEXT ) ;
@@ -1000,13 +1050,24 @@ define(function (require, exports, module) {
10001050 } ) ;
10011051
10021052 it ( "should no-op on Find Next with blank search" , function ( ) {
1003- myEditor . setCursorPos ( LINE_FIRST_REQUIRE , 0 ) ;
1053+ runs ( function ( ) {
1054+ // Make sure we have no previous query
1055+ twCommandManager . execute ( Commands . CMD_FIND ) ;
1056+ enterSearchText ( "" ) ;
1057+ pressEscape ( ) ;
1058+ } ) ;
10041059
1005- twCommandManager . execute ( Commands . CMD_FIND ) ;
1006- expect ( myEditor ) . toHaveCursorPosition ( LINE_FIRST_REQUIRE , 0 ) ;
1060+ waitsForSearchBarClose ( ) ;
10071061
1008- twCommandManager . execute ( Commands . CMD_FIND_NEXT ) ;
1009- expect ( myEditor ) . toHaveCursorPosition ( LINE_FIRST_REQUIRE , 0 ) ; // no change
1062+ runs ( function ( ) {
1063+ myEditor . setCursorPos ( LINE_FIRST_REQUIRE , 0 ) ;
1064+
1065+ twCommandManager . execute ( Commands . CMD_FIND ) ;
1066+ expect ( myEditor ) . toHaveCursorPosition ( LINE_FIRST_REQUIRE , 0 ) ;
1067+
1068+ twCommandManager . execute ( Commands . CMD_FIND_NEXT ) ;
1069+ expect ( myEditor ) . toHaveCursorPosition ( LINE_FIRST_REQUIRE , 0 ) ; // no change
1070+ } ) ;
10101071
10111072 } ) ;
10121073 } ) ;
0 commit comments