Skip to content

Commit 8695b02

Browse files
authored
refactor: Move the shortcut listing action into the shortcut dialog. (#307)
1 parent 6327ca7 commit 8695b02

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

src/navigation_controller.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -557,16 +557,6 @@ export class NavigationController {
557557
allowCollision: true,
558558
},
559559

560-
/** List all of the currently registered shortcuts. */
561-
announceShortcuts: {
562-
name: Constants.SHORTCUT_NAMES.LIST_SHORTCUTS,
563-
callback: () => {
564-
this.shortcutDialog.toggle();
565-
return true;
566-
},
567-
keyCodes: [KeyCodes.SLASH],
568-
},
569-
570560
/** Announce the current location of the cursor. */
571561
announceLocation: {
572562
name: Constants.SHORTCUT_NAMES.ANNOUNCE,
@@ -715,8 +705,9 @@ export class NavigationController {
715705
this.workspaceMovement.install();
716706

717707
this.clipboard.install();
708+
this.shortcutDialog.install();
718709

719-
// Initalise the shortcut modal with available shortcuts. Needs
710+
// Initialize the shortcut modal with available shortcuts. Needs
720711
// to be done separately rather at construction, as many shortcuts
721712
// are not registered at that point.
722713
this.shortcutDialog.createModalContent();
@@ -734,6 +725,7 @@ export class NavigationController {
734725
this.insertAction.uninstall();
735726
this.clipboard.uninstall();
736727
this.workspaceMovement.uninstall();
728+
this.shortcutDialog.uninstall();
737729

738730
this.removeShortcutHandlers();
739731
this.navigation.dispose();

src/shortcut_dialog.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,31 @@ export class ShortcutDialog {
158158
}
159159
}
160160
}
161+
162+
/**
163+
* Registers an action to list shortcuts with the shortcut registry.
164+
*/
165+
install() {
166+
/** List all of the currently registered shortcuts. */
167+
const announceShortcut: ShortcutRegistry.KeyboardShortcut = {
168+
name: Constants.SHORTCUT_NAMES.LIST_SHORTCUTS,
169+
callback: () => {
170+
this.toggle();
171+
return true;
172+
},
173+
keyCodes: [Blockly.utils.KeyCodes.SLASH],
174+
};
175+
ShortcutRegistry.registry.register(announceShortcut);
176+
}
177+
178+
/**
179+
* Unregisters the action to list shortcuts.
180+
*/
181+
uninstall() {
182+
ShortcutRegistry.registry.unregister(
183+
Constants.SHORTCUT_NAMES.LIST_SHORTCUTS,
184+
);
185+
}
161186
}
162187

163188
/**

0 commit comments

Comments
 (0)