@@ -210,6 +210,18 @@ define(function (require, exports, module) {
210210 _dispatchKeyInMdIframe ( "f" ) ;
211211 }
212212
213+ function _openSearch ( ) {
214+ if ( brackets . platform === "mac" ) {
215+ // Mac: use direct event emit to bypass nested iframe focus issues
216+ const win = _getMdIFrameWin ( ) ;
217+ if ( win && win . __toggleSearchForTest ) {
218+ win . __toggleSearchForTest ( ) ;
219+ return ;
220+ }
221+ }
222+ _openSearchWithCtrlF ( ) ;
223+ }
224+
213225 function _typeInSearch ( text ) {
214226 const input = _getMdIFrameDoc ( ) . getElementById ( "search-input" ) ;
215227 input . value = text ;
@@ -229,7 +241,17 @@ define(function (require, exports, module) {
229241
230242 async function _closeSearch ( ) {
231243 if ( _isSearchOpen ( ) ) {
232- _pressKeyInSearch ( "Escape" ) ;
244+ if ( brackets . platform === "mac" ) {
245+ // Mac: use toggle to avoid focus steal from Escape
246+ const win = _getMdIFrameWin ( ) ;
247+ if ( win && win . __toggleSearchForTest ) {
248+ win . __toggleSearchForTest ( ) ;
249+ } else {
250+ _pressKeyInSearch ( "Escape" ) ;
251+ }
252+ } else {
253+ _pressKeyInSearch ( "Escape" ) ;
254+ }
233255 await awaitsFor ( ( ) => ! _isSearchOpen ( ) , "search bar to close" ) ;
234256 }
235257 }
@@ -250,7 +272,7 @@ define(function (require, exports, module) {
250272 } , 10000 ) ;
251273
252274 it ( "should typing in search highlight matches" , async function ( ) {
253- _openSearchWithCtrlF ( ) ;
275+ _openSearch ( ) ;
254276 await awaitsFor ( ( ) => _isSearchOpen ( ) , "search bar to open" ) ;
255277
256278 _typeInSearch ( "Document" ) ;
@@ -262,7 +284,7 @@ define(function (require, exports, module) {
262284 } , 10000 ) ;
263285
264286 it ( "should match count show N/total format" , async function ( ) {
265- _openSearchWithCtrlF ( ) ;
287+ _openSearch ( ) ;
266288 await awaitsFor ( ( ) => _isSearchOpen ( ) , "search bar to open" ) ;
267289
268290 _typeInSearch ( "Document" ) ;
@@ -276,7 +298,7 @@ define(function (require, exports, module) {
276298 } , 10000 ) ;
277299
278300 it ( "should Enter navigate to next match" , async function ( ) {
279- _openSearchWithCtrlF ( ) ;
301+ _openSearch ( ) ;
280302 await awaitsFor ( ( ) => _isSearchOpen ( ) , "search bar to open" ) ;
281303
282304 _typeInSearch ( "Document" ) ;
@@ -296,7 +318,7 @@ define(function (require, exports, module) {
296318 } , 10000 ) ;
297319
298320 it ( "should Shift+Enter navigate to previous match" , async function ( ) {
299- _openSearchWithCtrlF ( ) ;
321+ _openSearch ( ) ;
300322 await awaitsFor ( ( ) => _isSearchOpen ( ) , "search bar to open" ) ;
301323
302324 _typeInSearch ( "Document" ) ;
@@ -319,7 +341,7 @@ define(function (require, exports, module) {
319341 } , 10000 ) ;
320342
321343 it ( "should navigation wrap around" , async function ( ) {
322- _openSearchWithCtrlF ( ) ;
344+ _openSearch ( ) ;
323345 await awaitsFor ( ( ) => _isSearchOpen ( ) , "search bar to open" ) ;
324346
325347 _typeInSearch ( "Document" ) ;
@@ -345,7 +367,7 @@ define(function (require, exports, module) {
345367 } , 10000 ) ;
346368
347369 it ( "should Escape close search and restore focus" , async function ( ) {
348- _openSearchWithCtrlF ( ) ;
370+ _openSearch ( ) ;
349371 await awaitsFor ( ( ) => _isSearchOpen ( ) , "search bar to open" ) ;
350372
351373 _typeInSearch ( "test" ) ;
@@ -364,7 +386,7 @@ define(function (require, exports, module) {
364386 } , 10000 ) ;
365387
366388 it ( "should closing search clear all highlights" , async function ( ) {
367- _openSearchWithCtrlF ( ) ;
389+ _openSearch ( ) ;
368390 await awaitsFor ( ( ) => _isSearchOpen ( ) , "search bar to open" ) ;
369391
370392 _typeInSearch ( "Document" ) ;
@@ -376,7 +398,7 @@ define(function (require, exports, module) {
376398 } , 10000 ) ;
377399
378400 it ( "should close button close search" , async function ( ) {
379- _openSearchWithCtrlF ( ) ;
401+ _openSearch ( ) ;
380402 await awaitsFor ( ( ) => _isSearchOpen ( ) , "search bar to open" ) ;
381403
382404 _typeInSearch ( "test" ) ;
@@ -389,7 +411,7 @@ define(function (require, exports, module) {
389411 } , 10000 ) ;
390412
391413 it ( "should search start from 1 character" , async function ( ) {
392- _openSearchWithCtrlF ( ) ;
414+ _openSearch ( ) ;
393415 await awaitsFor ( ( ) => _isSearchOpen ( ) , "search bar to open" ) ;
394416
395417 _typeInSearch ( "D" ) ;
@@ -400,7 +422,7 @@ define(function (require, exports, module) {
400422 } , 10000 ) ;
401423
402424 it ( "should Escape in search NOT forward to Phoenix" , async function ( ) {
403- _openSearchWithCtrlF ( ) ;
425+ _openSearch ( ) ;
404426 await awaitsFor ( ( ) => _isSearchOpen ( ) , "search bar to open" ) ;
405427
406428 let escapeSent = false ;
0 commit comments