Move shortcut listener into service
Google-Bug-Id: b/199305453
Change-Id: I61e0b678746c61a0e10119075c89815e567acd4e
diff --git a/polygerrit-ui/app/elements/core/gr-keyboard-shortcuts-dialog/gr-keyboard-shortcuts-dialog.ts b/polygerrit-ui/app/elements/core/gr-keyboard-shortcuts-dialog/gr-keyboard-shortcuts-dialog.ts
index 0b191f1..541d877 100644
--- a/polygerrit-ui/app/elements/core/gr-keyboard-shortcuts-dialog/gr-keyboard-shortcuts-dialog.ts
+++ b/polygerrit-ui/app/elements/core/gr-keyboard-shortcuts-dialog/gr-keyboard-shortcuts-dialog.ts
@@ -27,6 +27,7 @@
SectionView,
} from '../../../mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin';
import {property, customElement} from '@polymer/decorators';
+import {appContext} from '../../../services/app-context';
declare global {
interface HTMLElementTagNameMap {
@@ -60,13 +61,14 @@
@property({type: Array})
_right?: SectionShortcut[];
- private keyboardShortcutDirectoryListener: ShortcutListener;
+ private readonly shortcutListener: ShortcutListener;
+
+ private readonly shortcuts = appContext.shortcutsService;
constructor() {
super();
- this.keyboardShortcutDirectoryListener = (
- d?: Map<ShortcutSection, SectionView>
- ) => this._onDirectoryUpdated(d);
+ this.shortcutListener = (d?: Map<ShortcutSection, SectionView>) =>
+ this._onDirectoryUpdated(d);
}
override ready() {
@@ -76,15 +78,11 @@
override connectedCallback() {
super.connectedCallback();
- this.addKeyboardShortcutDirectoryListener(
- this.keyboardShortcutDirectoryListener
- );
+ this.shortcuts.addListener(this.shortcutListener);
}
override disconnectedCallback() {
- this.removeKeyboardShortcutDirectoryListener(
- this.keyboardShortcutDirectoryListener
- );
+ this.shortcuts.removeListener(this.shortcutListener);
super.disconnectedCallback();
}
diff --git a/polygerrit-ui/app/mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin.ts b/polygerrit-ui/app/mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin.ts
index 3ea612e..b36b4c0 100644
--- a/polygerrit-ui/app/mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin.ts
+++ b/polygerrit-ui/app/mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin.ts
@@ -377,14 +377,6 @@
return {};
}
- addKeyboardShortcutDirectoryListener(listener: ShortcutListener) {
- this.shortcuts.addListener(listener);
- }
-
- removeKeyboardShortcutDirectoryListener(listener: ShortcutListener) {
- this.shortcuts.removeListener(listener);
- }
-
_handleVKeyDown(e: CustomKeyboardEvent) {
if (this.shouldSuppressKeyboardShortcut(e)) return;
this._shortcut_v_key_last_pressed = Date.now();
@@ -491,8 +483,6 @@
bindShortcut(shortcut: Shortcut, ...bindings: string[]): void;
shouldSuppressKeyboardShortcut(event: CustomKeyboardEvent): boolean;
modifierPressed(event: CustomKeyboardEvent): boolean;
- addKeyboardShortcutDirectoryListener(listener: ShortcutListener): void;
- removeKeyboardShortcutDirectoryListener(listener: ShortcutListener): void;
}
export interface KeyboardShortcutMixinInterfaceTesting {