From 092707371d0c387c3ee9522b77bef3a72c62797f Mon Sep 17 00:00:00 2001 From: Kristina Durivage Date: Fri, 20 Jan 2023 17:01:13 -0600 Subject: [PATCH] Add list of bindings for updating on change --- public/app/core/services/keybindingSrv.ts | 8 ++++++++ public/app/features/explore/ExplorePage.tsx | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/public/app/core/services/keybindingSrv.ts b/public/app/core/services/keybindingSrv.ts index b48bbbe1650..2b16301d35a 100644 --- a/public/app/core/services/keybindingSrv.ts +++ b/public/app/core/services/keybindingSrv.ts @@ -29,9 +29,11 @@ import { withFocusedPanel } from './withFocusedPanelId'; export class KeybindingSrv { constructor(private locationService: LocationService, private chromeService: AppChromeService) {} + bindings: string[] = []; clearAndInitGlobalBindings() { Mousetrap.reset(); + this.bindings = []; if (this.locationService.getLocation().pathname !== '/login') { this.bind(['?', 'h'], this.showHelpModal); @@ -164,6 +166,9 @@ export class KeybindingSrv { } bind(keyArg: string | string[], fn: () => void) { + const keyArgArr = Array.isArray(keyArg) ? keyArg : [keyArg]; + this.bindings.push(...keyArgArr); + Mousetrap.bind( keyArg, (evt) => { @@ -177,6 +182,8 @@ export class KeybindingSrv { } bindGlobal(keyArg: string, fn: () => void) { + this.bindings.push(keyArg); + Mousetrap.bindGlobal( keyArg, (evt) => { @@ -190,6 +197,7 @@ export class KeybindingSrv { } unbind(keyArg: string, keyType?: string) { + this.bindings = this.bindings.filter((binding) => binding !== keyArg); Mousetrap.unbind(keyArg, keyType); } diff --git a/public/app/features/explore/ExplorePage.tsx b/public/app/features/explore/ExplorePage.tsx index 10400900e90..2cdc0a3014a 100644 --- a/public/app/features/explore/ExplorePage.tsx +++ b/public/app/features/explore/ExplorePage.tsx @@ -54,7 +54,7 @@ export function ExplorePage(props: GrafanaRouteComponentProps<{}, ExploreQueryPa useEffect(() => { keybindings.setupTimeRangeBindings(false); - }, [keybindings]); + }, [keybindings, keybindings.bindings]); useEffect(() => { if (!config.featureToggles.correlations) {