Toolbelt.Blazor.HotKeys2 icon indicating copy to clipboard operation
Toolbelt.Blazor.HotKeys2 copied to clipboard

Example not working

Open Martin-Andersen opened this issue 2 years ago • 5 comments

In the old version of HotKeys. I wrote this

HotKeysContext = HotKeys.CreateContext()
                .Add(ModKeys.Ctrl, Keys.K, SetFocusInGridSearchField, "Set focus in grid search field");

I tried this in v2, not working

HotKeysContext = HotKeys.CreateContext()
            .Add(ModCode.Ctrl,Key.k, SetFocusInGridSearchField, "Set focus in grid search field");

And this not working

HotKeysContext = HotKeys.CreateContext()
            .Add(ModCode.Ctrl,Key.k, "Set focus in grid search field", _ => SetFocusInGridSearchField);

Is it because my handler is async?

private async Task SetFocusInGridSearchField()
    {
        await JsRuntime.InvokeVoidAsync("focusElement", GridSearchBoxPortfolioListGrid);
    }

Martin-Andersen avatar Feb 06 '23 13:02 Martin-Andersen

Better headline

Martin-Andersen avatar Feb 06 '23 13:02 Martin-Andersen

@Martin-Andersen Currently, it is intentionally by design.

See also: https://github.com/jsakamoto/Toolbelt.Blazor.HotKeys2/issues/7#issuecomment-1372142048

jsakamoto avatar Feb 06 '23 14:02 jsakamoto

This also tripped me up a bit as the errors in Visual Studio are not that great.

Would be a great idea to add a note in the sample to the async method exception.

Pinox avatar Sep 01 '23 17:09 Pinox

Just a +1 here. Had an async Task method called on button click, tried to wire up a shortcut to call the same method per the sample, it can't resolve the method, and I get a thousand other overload options to scroll through.

My understanding of ValueTask is it's only of performance improvement if the underlyng async operation completes synchronously...They also have a drastically reduced API surface area (by design). See https://devblogs.microsoft.com/dotnet/understanding-the-whys-whats-and-whens-of-valuetask/

wokket avatar Jan 24 '24 07:01 wokket

Hi everyone, I've changed my opinion that I don't provide the Add() methods of overloaded version for async Task because so many developers were confused by my decision.

So, the latest preview version of the HotKeys2 now starts to support async Task for its Add() method.

See also: https://www.nuget.org/packages/Toolbelt.Blazor.HotKeys2/3.3.0-preview.1#releasenotes-body-tab

jsakamoto avatar Jan 27 '24 07:01 jsakamoto