From 1013d74f13f27c53ae0abcb1a1a9072b1afd3a77 Mon Sep 17 00:00:00 2001 From: Jesse David Peterson Date: Tue, 9 Dec 2025 13:35:43 -0500 Subject: [PATCH] TimeRange: Additional keyboard shortcut `t =` to complement `t +` for zoom in (#115022) feat(time-range): additional keyboard shortcut "t =" for zoom in --- public/app/core/services/keybindingSrv.ts | 4 +++ .../scene/keyboardShortcuts.test.ts | 31 +++++++++++++++++++ .../scene/keyboardShortcuts.ts | 7 +++++ 3 files changed, 42 insertions(+) diff --git a/public/app/core/services/keybindingSrv.ts b/public/app/core/services/keybindingSrv.ts index ea232baffcc..2cbda7827e3 100644 --- a/public/app/core/services/keybindingSrv.ts +++ b/public/app/core/services/keybindingSrv.ts @@ -236,6 +236,10 @@ export class KeybindingSrv { appEvents.publish(new ZoomOutEvent({ scale: 0.5, updateUrl })); }); + this.bind('t =', () => { + appEvents.publish(new ZoomOutEvent({ scale: 0.5, updateUrl })); + }); + this.bind('t -', () => { appEvents.publish(new ZoomOutEvent({ scale: 2, updateUrl })); }); diff --git a/public/app/features/dashboard-scene/scene/keyboardShortcuts.test.ts b/public/app/features/dashboard-scene/scene/keyboardShortcuts.test.ts index 9a70858f39b..8772d49f138 100644 --- a/public/app/features/dashboard-scene/scene/keyboardShortcuts.test.ts +++ b/public/app/features/dashboard-scene/scene/keyboardShortcuts.test.ts @@ -269,6 +269,13 @@ describe('setupKeyboardShortcuts', () => { expect(tPlusBinding).toBeDefined(); }); + it('should setup t = zoom in shortcut', () => { + setupKeyboardShortcuts(mockScene); + + const tEqualsBinding = mockKeybindingSet.addBinding.mock.calls.find((call) => call[0].key === 't ='); + expect(tEqualsBinding).toBeDefined(); + }); + it('should setup t - zoom out shortcut with keypress type', () => { setupKeyboardShortcuts(mockScene); @@ -302,9 +309,11 @@ describe('setupKeyboardShortcuts', () => { setupKeyboardShortcuts(mockScene); const tPlusBinding = mockKeybindingSet.addBinding.mock.calls.find((call) => call[0].key === 't +'); + const tEqualsBinding = mockKeybindingSet.addBinding.mock.calls.find((call) => call[0].key === 't ='); const tMinusBinding = mockKeybindingSet.addBinding.mock.calls.find((call) => call[0].key === 't -'); expect(tPlusBinding).toBeUndefined(); + expect(tEqualsBinding).toBeUndefined(); expect(tMinusBinding).toBeUndefined(); }); }); @@ -364,6 +373,28 @@ describe('setupKeyboardShortcuts', () => { expect(newSpan).toBe(3 * 60 * 60 * 1000); // 3 hours in milliseconds }); + it('should zoom in (scale 0.5) when t = is pressed', () => { + setupKeyboardShortcuts(mockScene); + + const tEqualsBinding = mockKeybindingSet.addBinding.mock.calls.find((call) => call[0].key === 't ='); + const handler = tEqualsBinding![0].onTrigger; + + handler(); + + // Scale 0.5 should result in 3 hour span (half of 6) + expect(mockTimeRange.onTimeRangeChange).toHaveBeenCalledWith( + expect.objectContaining({ + from: expect.any(Object), + to: expect.any(Object), + raw: expect.any(Object), + }) + ); + + const call = mockTimeRange.onTimeRangeChange.mock.calls[0][0]; + const newSpan = call.to.valueOf() - call.from.valueOf(); + expect(newSpan).toBe(3 * 60 * 60 * 1000); // 3 hours in milliseconds + }); + it('should keep center point when zooming in', () => { setupKeyboardShortcuts(mockScene); diff --git a/public/app/features/dashboard-scene/scene/keyboardShortcuts.ts b/public/app/features/dashboard-scene/scene/keyboardShortcuts.ts index 1113b8a8a8c..f1878aeb466 100644 --- a/public/app/features/dashboard-scene/scene/keyboardShortcuts.ts +++ b/public/app/features/dashboard-scene/scene/keyboardShortcuts.ts @@ -138,6 +138,13 @@ export function setupKeyboardShortcuts(scene: DashboardScene) { }, }); + keybindings.addBinding({ + key: 't =', + onTrigger: () => { + handleZoom(scene, 0.5); + }, + }); + keybindings.addBinding({ key: 't -', type: 'keypress', // NOTE: Because some browsers/OS identify minus symbol differently.