Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcuts: in some circonstance, ShortcutRegistration.remove() doesn't work! #5480

Closed
sandronm opened this issue Apr 12, 2019 · 1 comment · Fixed by #6427
Closed

Shortcuts: in some circonstance, ShortcutRegistration.remove() doesn't work! #5480

sandronm opened this issue Apr 12, 2019 · 1 comment · Fixed by #6427
Labels
BFP Bugfix priority, also known as Warranty bug Shortcut API
Milestone

Comments

@sandronm
Copy link

sandronm commented Apr 12, 2019

Hello!

This is a tricky bug discovered on version 13.0.3 and also 13.0.2

	Button button;
	ShortcutRegistration shortcutRegistration;

	public void init() {

		button = new Button();
		button.setText("Reactivate shortcut");
		button.addClickListener(event -> shortcutRegistration = buildShortcut());
		button.setEnabled(false);
		add(button);

		add(new TextField());
		shortcutRegistration = buildShortcut();

		Button otherButton = new Button();
		otherButton.setText("a button with shortcutlistener");
		otherButton.addClickListener(event -> new Notification("Shortcut B has been triggered", 1000).open());
		// Disable the following line to make it works! :/
		otherButton.addClickShortcut(Key.KEY_B);
		add(otherButton);
	}

	private ShortcutRegistration buildShortcut() {
		return Shortcuts.addShortcutListener(this, () -> {
			new Notification("Shortcut C has been triggered", 1000).open();
			shortcutRegistration.remove();
			button.setEnabled(true);
		}, Key.KEY_C);
	}

I add a "button", a basic textfield and an "otherButton" in my page.
I also define 2 shortcuts:

  • "KEY_C" on my page: when this one is triggered, it will remove itself => should be triggered only once but it can be "reactivate" by clicking on "button".
  • "KEY_B" as clickShortcut on my otherButton: it does nothing special, it's just a shortcut :)

When the page is loaded, I focus the textfield and I press "c"
=> Shortcut KEY_C is triggered and should be removed. The letter "c" doesn't appear in my textfield.
As expected, if a press again "c", because Shortcut KEY_C has been removed, the letter "c" should appear in my textfield but it's not the case.

I make a lot of investigation to understand what's going on and I finally discovered the cause of this bug: the line otherButton.addClickShortcut(Key.KEY_B);
If you comment it, the shortcut KEY_C will be correctly removed.

Tricky one... :-)

@ujoni
Copy link
Contributor

ujoni commented Apr 12, 2019

The cause might be related to #5090

@pleku pleku added the BFP Bugfix priority, also known as Warranty label Sep 10, 2019
ujoni pushed a commit that referenced this issue Sep 10, 2019
ujoni added a commit that referenced this issue Sep 12, 2019
mehdi-vaadin pushed a commit that referenced this issue Sep 13, 2019
* Verify #5480

(cherry picked from commit aa915fb)
mehdi-vaadin pushed a commit that referenced this issue Sep 13, 2019
* Verify #5480

(cherry picked from commit aa915fb)
@mehdi-vaadin mehdi-vaadin added this to the 2.0.12 milestone Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BFP Bugfix priority, also known as Warranty bug Shortcut API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants