@@ -49,7 +49,8 @@ define(function (require, exports, module) {
4949 ProjectManager ,
5050 SearchResultsView ,
5151 testWindow ,
52- $ ;
52+ $ ,
53+ __PR ;
5354
5455 beforeAll ( async function ( ) {
5556 await SpecRunnerUtils . createTempDirectory ( ) ;
@@ -71,6 +72,7 @@ define(function (require, exports, module) {
7172 SearchResultsView = testWindow . brackets . test . SearchResultsView ;
7273 $ = testWindow . $ ;
7374 PreferencesManager = testWindow . brackets . test . PreferencesManager ;
75+ __PR = testWindow . __PR ;
7476 PreferencesManager . set ( "findInFiles.nodeSearch" , false ) ;
7577 PreferencesManager . set ( "findInFiles.instantSearch" , false ) ;
7678 PreferencesManager . set ( "maxSearchHistory" , 5 ) ;
@@ -89,6 +91,8 @@ define(function (require, exports, module) {
8991 $ = null ;
9092 testWindow = null ;
9193 PreferencesManager = null ;
94+ __PR = null ;
95+
9296 await SpecRunnerUtils . closeTestWindow ( ) ;
9397 await SpecRunnerUtils . removeTempDirectory ( ) ;
9498 } , 30000 ) ;
@@ -125,6 +129,10 @@ define(function (require, exports, module) {
125129 } ) ;
126130 }
127131
132+ function getSearchField ( ) {
133+ return $ ( "#find-what" ) ;
134+ }
135+
128136 async function closeSearchBar ( ) {
129137 FindInFilesUI . _closeFindBar ( ) ;
130138 await waitForSearchBarClose ( ) ;
@@ -571,6 +579,28 @@ define(function (require, exports, module) {
571579 // Search model shouldn't be cleared after search bar closed without running a search
572580 expect ( Object . keys ( FindInFiles . searchModel . results ) . length ) . not . toBe ( 0 ) ;
573581 } ) ;
582+
583+ it ( "should switch between find replace and find in files with selection work as expected" , async function ( ) {
584+ await closeSearchBar ( ) ;
585+ const filePath = testPath + "/foo.js" ;
586+ await __PR . openFile ( filePath ) ;
587+ __PR . setCursors ( [ "7:5-7:13" ] ) ; // select text: function
588+ CommandManager . execute ( Commands . CMD_FIND ) ;
589+
590+ expect ( getSearchField ( ) . val ( ) ) . toEql ( "function" ) ;
591+
592+ CommandManager . execute ( Commands . CMD_FIND_IN_FILES ) ;
593+ await awaitsFor ( ( ) => {
594+ return $ ( "#find-in-files-results .contracting-col" ) . text ( ) === "function" ;
595+ } , ( ) => {
596+ return `Find in files search to be function but got${ $ ( "#find-in-files-results .contracting-col" ) . text ( ) } ` ;
597+ } ) ;
598+
599+ __PR . setCursors ( [ "5:15-5:22" ] ) ; // select text: require
600+ CommandManager . execute ( Commands . CMD_FIND ) ;
601+ expect ( getSearchField ( ) . val ( ) ) . toEql ( "require" ) ;
602+ await openSearchBar ( ) ;
603+ } ) ;
574604 } ) ;
575605 } ) ;
576606} ) ;
0 commit comments