Flow: Shortcuts: command is executed twice when you have 2 shortcuts with same key but different key modifiers

Created on 10 Apr 2019  路  1Comment  路  Source: vaadin/flow

Hello!

I'm currently using Vaadin 13.0.3 but the issue also exists with version 13.0.2.

Here is my simple code:

        Shortcuts.addShortcutListener(this, () -> add(new Span("KEY_H")), Key.KEY_H);
        Shortcuts.addShortcutListener(this, () -> add(new Span("CTRL + KEY_H")), Key.KEY_H, KeyModifier.CONTROL);

        ShortcutEventListener listener = event -> {
            if (event.matches(Key.KEY_Y)) {
                add(new Span("KEY_Y"));
            }
            else if (event.matches(Key.KEY_Y, KeyModifier.CONTROL)) {
                add(new Span("CTRL + KEY_Y"));
            }
        };

        UI.getCurrent().addShortcutListener(listener, Key.KEY_Y);
        UI.getCurrent().addShortcutListener(listener, Key.KEY_Y, KeyModifier.CONTROL);

I defined 4 shortcuts: H, CTRL + H, Y and CTRL + Y

When I press in my browser CTRL + H or CTRL + Y, I will also add the span "KEY_H" (or "KEY_Y") before the "CTRL + KEY_H" or "CTRL + KEY_Y" => there are 2 events triggered instead of one (CTRL + H or CTRL + Y).

I looked at the browser side and I can confirm only one XHR request is send back to the server containing the correct key but also the correct keymodifier.
=> The issue must comes from Flow.

Thank you for your fix ;-)

BFP Shortcut API bug

Most helpful comment

It also occurs in Vaadin 14.0.4. @sandronm please note that Vaadin 13 is not supported anymore and this issue will be fixed in Vaadin 14.

>All comments

It also occurs in Vaadin 14.0.4. @sandronm please note that Vaadin 13 is not supported anymore and this issue will be fixed in Vaadin 14.

Was this page helpful?
0 / 5 - 0 ratings