@@ -431,37 +431,43 @@ const checkIfEnabledForUrl = async () => {
431
431
if ( ! isEnabledForUrl ) HUD . hide ( true , false ) ;
432
432
} ;
433
433
434
- // If we are in the help dialog iframe, then HelpDialog is already defined with the necessary
435
- // functions.
436
- if ( globalThis . HelpDialog == null ) {
437
- globalThis . HelpDialog = {
438
- helpUI : null ,
439
- isShowing ( ) {
440
- return this . helpUI && this . helpUI . showing ;
441
- } ,
442
- abort ( ) {
443
- if ( this . isShowing ( ) ) {
444
- return this . helpUI . hide ( false ) ;
445
- }
446
- } ,
434
+ // If this content script is running in the help dialog's iframe, then use the HelpDialogPage's
435
+ // methods to control the dialog. Otherwise, load the help dialog in a UIComponent iframe.
436
+ const HelpDialog = {
437
+ helpUI : null ,
438
+
439
+ isShowing ( ) {
440
+ if ( globalThis . isVimiumHelpDialogPage ) return true ;
441
+ return this . helpUI && this . helpUI . showing ;
442
+ } ,
447
443
448
- async toggle ( request ) {
449
- if ( this . helpUI == null ) {
450
- await DomUtils . documentComplete ( ) ;
451
- this . helpUI = new UIComponent ( ) ;
452
- this . helpUI . load ( "pages/help_dialog_page.html" , "vimium-help-dialog-frame" ) ;
453
- }
454
- if ( this . isShowing ( ) ) {
455
- this . helpUI . hide ( ) ;
456
- } else {
457
- return this . helpUI . show (
458
- { name : "activate" } ,
459
- { focus : true , sourceFrameId : request . sourceFrameId } ,
460
- ) ;
461
- }
462
- } ,
463
- } ;
464
- }
444
+ abort ( ) {
445
+ if ( globalThis . isVimiumHelpDialogPage ) throw new Error ( "This should be impossible." ) ;
446
+ if ( this . isShowing ( ) ) {
447
+ return this . helpUI . hide ( false ) ;
448
+ }
449
+ } ,
450
+
451
+ async toggle ( request ) {
452
+ // If we're in the help dialog page already and the user has typed a key to show the help
453
+ // dialog, then we should hide it.
454
+ if ( globalThis . isVimiumHelpDialogPage ) return HelpDialogPage . hide ( ) ;
455
+
456
+ if ( this . helpUI == null ) {
457
+ await DomUtils . documentComplete ( ) ;
458
+ this . helpUI = new UIComponent ( ) ;
459
+ this . helpUI . load ( "pages/help_dialog_page.html" , "vimium-help-dialog-frame" ) ;
460
+ }
461
+ if ( this . isShowing ( ) ) {
462
+ this . helpUI . hide ( ) ;
463
+ } else {
464
+ return this . helpUI . show (
465
+ { name : "activate" } ,
466
+ { focus : true , sourceFrameId : request . sourceFrameId } ,
467
+ ) ;
468
+ }
469
+ } ,
470
+ } ;
465
471
466
472
const testEnv = globalThis . window == null ;
467
473
if ( ! testEnv ) {
@@ -471,6 +477,7 @@ if (!testEnv) {
471
477
}
472
478
473
479
Object . assign ( globalThis , {
480
+ HelpDialog,
474
481
handlerStack,
475
482
windowIsFocused,
476
483
// These are exported for normal mode and link-hints mode.
0 commit comments