@@ -70,8 +70,8 @@ class SearchResultsManager {
70
70
}
71
71
return this . searchResults [ this . focusedIndex ] . anchor ;
72
72
}
73
- const isLink = focusedElement . localName === 'a' &&
74
- focusedElement . hasAttribute ( 'href' ) ;
73
+ const isLink =
74
+ focusedElement . localName === 'a' && focusedElement . hasAttribute ( 'href' ) ;
75
75
if ( ! linkOnly || isLink ) {
76
76
return focusedElement ;
77
77
}
@@ -214,7 +214,8 @@ class WebSearchNavigator {
214
214
215
215
initSearchInputNavigation ( ) {
216
216
const searchInput = document . querySelector (
217
- this . searchEngine . searchBoxSelector ) ;
217
+ this . searchEngine . searchBoxSelector ,
218
+ ) ;
218
219
if ( searchInput == null ) {
219
220
return ;
220
221
}
@@ -235,8 +236,10 @@ class WebSearchNavigator {
235
236
return ! shouldHandleSearchInputKey ( event ) ;
236
237
}
237
238
const element = document . activeElement ;
238
- if ( element . isContentEditable || [ 'textarea' , 'input' ] . includes (
239
- element . tagName . toLowerCase ( ) ) ) {
239
+ if (
240
+ element . isContentEditable ||
241
+ [ 'textarea' , 'input' ] . includes ( element . tagName . toLowerCase ( ) )
242
+ ) {
240
243
return true ;
241
244
}
242
245
// Scroll to the search box in case it's outside the viewport so that it's
@@ -252,13 +255,17 @@ class WebSearchNavigator {
252
255
return true ;
253
256
}
254
257
// Everything is selected; deselect all.
255
- if ( searchInput . selectionStart === 0 &&
256
- searchInput . selectionEnd === searchInput . value . length ) {
258
+ if (
259
+ searchInput . selectionStart === 0 &&
260
+ searchInput . selectionEnd === searchInput . value . length
261
+ ) {
257
262
// Scroll to the search box in case it's outside the viewport so that
258
263
// it's clear to the user that it has focus.
259
264
scrollToElement ( this . searchEngine , searchInput ) ;
260
265
searchInput . setSelectionRange (
261
- searchInput . value . length , searchInput . value . length ) ;
266
+ searchInput . value . length ,
267
+ searchInput . value . length ,
268
+ ) ;
262
269
return false ;
263
270
}
264
271
// Closing search suggestions via document.body.click() or
@@ -274,15 +281,21 @@ class WebSearchNavigator {
274
281
// focus.
275
282
return true ;
276
283
} ;
277
- this . register ( this . options . sync . get ( 'focusSearchInput' ) ,
278
- outsideSearchboxHandler ) ;
284
+ this . register (
285
+ this . options . sync . get ( 'focusSearchInput' ) ,
286
+ outsideSearchboxHandler ,
287
+ ) ;
279
288
// Bind globally, otherwise Mousetrap ignores keypresses inside inputs.
280
289
// We must bind it separately to the search box element, or otherwise the
281
290
// key event won't always be captured (for example this is the case on
282
291
// Google Search as of 2020-06-22), presumably because the javascript in the
283
292
// page will disable further processing.
284
- this . register ( this . options . sync . get ( 'focusSearchInput' ) ,
285
- insideSearchboxHandler , searchInput , true ) ;
293
+ this . register (
294
+ this . options . sync . get ( 'focusSearchInput' ) ,
295
+ insideSearchboxHandler ,
296
+ searchInput ,
297
+ true ,
298
+ ) ;
286
299
}
287
300
288
301
initTabsNavigation ( ) {
@@ -321,15 +334,18 @@ class WebSearchNavigator {
321
334
resetResultsManager ( ) {
322
335
if ( this . resultsManager != null ) {
323
336
const searchResult = this . resultsManager . searchResults [
324
- this . resultsManager . focusedIndex ] ;
337
+ this . resultsManager . focusedIndex
338
+ ] ;
325
339
// NOTE: it seems that search results can become undefined when the DOM
326
340
// elements are removed (for example when the results change).
327
341
if ( searchResult != null ) {
328
342
this . resultsManager . unhighlight ( searchResult ) ;
329
343
}
330
344
}
331
- this . resultsManager = new SearchResultsManager ( this . searchEngine ,
332
- this . options . sync . getAll ( ) ) ;
345
+ this . resultsManager = new SearchResultsManager (
346
+ this . searchEngine ,
347
+ this . options . sync . getAll ( ) ,
348
+ ) ;
333
349
this . resultsManager . reloadSearchResults ( ) ;
334
350
this . isFirstNavigation = true ;
335
351
if ( this . resultsManager . searchResults . length === 0 ) {
@@ -371,15 +387,15 @@ class WebSearchNavigator {
371
387
}
372
388
return false ;
373
389
} ) ;
374
- this . register ( getOpt ( 'navigateKey' ) , ( ) => {
390
+ this . register ( getOpt ( 'navigateKey' ) , async ( ) => {
375
391
const link = this . resultsManager . getElementToNavigate ( ) ;
376
392
if ( link == null ) {
377
393
return true ;
378
394
}
379
395
const lastNavigation = this . options . local . values ;
380
396
lastNavigation . lastQueryUrl = location . href ;
381
397
lastNavigation . lastFocusedIndex = this . resultsManager . focusedIndex ;
382
- this . options . local . save ( ) ;
398
+ await this . options . local . save ( ) ;
383
399
// If the element is a link, use the href to directly navigate, since some
384
400
// websites will open it in a new tab.
385
401
if ( link . localName === 'a' && link . href ) {
@@ -427,21 +443,29 @@ class WebSearchNavigator {
427
443
return this . options . sync . get ( key ) ;
428
444
} ;
429
445
this . register ( getOpt ( 'navigateShowAll' ) , ( ) =>
430
- this . searchEngine . changeTools ( 'a' ) ) ;
446
+ this . searchEngine . changeTools ( 'a' ) ,
447
+ ) ;
431
448
this . register ( getOpt ( 'navigateShowHour' ) , ( ) =>
432
- this . searchEngine . changeTools ( 'h' ) ) ;
449
+ this . searchEngine . changeTools ( 'h' ) ,
450
+ ) ;
433
451
this . register ( getOpt ( 'navigateShowDay' ) , ( ) =>
434
- this . searchEngine . changeTools ( 'd' ) ) ;
452
+ this . searchEngine . changeTools ( 'd' ) ,
453
+ ) ;
435
454
this . register ( getOpt ( 'navigateShowWeek' ) , ( ) =>
436
- this . searchEngine . changeTools ( 'w' ) ) ;
455
+ this . searchEngine . changeTools ( 'w' ) ,
456
+ ) ;
437
457
this . register ( getOpt ( 'navigateShowMonth' ) , ( ) =>
438
- this . searchEngine . changeTools ( 'm' ) ) ;
458
+ this . searchEngine . changeTools ( 'm' ) ,
459
+ ) ;
439
460
this . register ( getOpt ( 'navigateShowYear' ) , ( ) =>
440
- this . searchEngine . changeTools ( 'y' ) ) ;
461
+ this . searchEngine . changeTools ( 'y' ) ,
462
+ ) ;
441
463
this . register ( getOpt ( 'toggleVerbatimSearch' ) , ( ) =>
442
- this . searchEngine . changeTools ( 'v' ) ) ;
464
+ this . searchEngine . changeTools ( 'v' ) ,
465
+ ) ;
443
466
this . register ( getOpt ( 'toggleSort' ) , ( ) =>
444
- this . searchEngine . changeTools ( null ) ) ;
467
+ this . searchEngine . changeTools ( null ) ,
468
+ ) ;
445
469
}
446
470
447
471
register ( shortcuts , callback , element = document , global = false ) {
0 commit comments