diff --git a/src/Aspire.Dashboard/Components/Controls/SummaryDetailsView.razor.cs b/src/Aspire.Dashboard/Components/Controls/SummaryDetailsView.razor.cs index a96e5c944c..df8c5d8795 100644 --- a/src/Aspire.Dashboard/Components/Controls/SummaryDetailsView.razor.cs +++ b/src/Aspire.Dashboard/Components/Controls/SummaryDetailsView.razor.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Globalization; +using Aspire.Dashboard.Extensions; using Aspire.Dashboard.Model; using Aspire.Dashboard.Utils; using Microsoft.AspNetCore.Components; @@ -188,7 +189,7 @@ private void SetPanelSizes(float panel1Fraction) public async Task OnPageKeyDownAsync(KeyboardEventArgs args) { - if (_splitterRef is null || !args.ShiftKey) + if (_splitterRef is null || !args.OnlyShiftPressed()) { return; } diff --git a/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs b/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs index 89a5c42808..20b866ea40 100644 --- a/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs +++ b/src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using Aspire.Dashboard.Components.Dialogs; +using Aspire.Dashboard.Extensions; using Aspire.Dashboard.Model; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; @@ -153,7 +154,7 @@ public async Task LaunchSettingsAsync() public async Task OnPageKeyDownAsync(KeyboardEventArgs args) { - if (args.ShiftKey) + if (args.OnlyShiftPressed()) { if (args.Key is "?") { @@ -164,15 +165,15 @@ public async Task OnPageKeyDownAsync(KeyboardEventArgs args) await LaunchSettingsAsync(); } } - else + else if (args.NoModifiersPressed()) { var url = args.Key.ToLower() switch { "r" => "/", - "c" => "/ConsoleLogs", - "s" => "/StructuredLogs", - "t" => "/Traces", - "m" => "/Metrics", + "c" => "/consolelogs", + "s" => "/structuredlogs", + "t" => "/traces", + "m" => "/metrics", _ => null }; @@ -189,7 +190,7 @@ public async ValueTask DisposeAsync() _themeChangedSubscription?.Dispose(); _locationChangingRegistration?.Dispose(); ShortcutManager.RemoveGlobalKeydownListener(this); - + try { await JS.InvokeVoidAsync("window.unregisterGlobalKeydownListener", _keyboardHandlers); diff --git a/src/Aspire.Dashboard/Extensions/KeyboardEventArgsExtensions.cs b/src/Aspire.Dashboard/Extensions/KeyboardEventArgsExtensions.cs new file mode 100644 index 0000000000..37de21e8bb --- /dev/null +++ b/src/Aspire.Dashboard/Extensions/KeyboardEventArgsExtensions.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.AspNetCore.Components.Web; + +namespace Aspire.Dashboard.Extensions; + +internal static class KeyboardEventArgsExtensions +{ + public static bool NoModifiersPressed(this KeyboardEventArgs args) + { + return !args.AltKey && !args.CtrlKey && !args.MetaKey && !args.ShiftKey; + } + + public static bool OnlyShiftPressed(this KeyboardEventArgs args) + { + return args.ShiftKey && !args.AltKey && !args.CtrlKey && !args.MetaKey; + } +}