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

Added a way to unregister keybindings for a command #8269

Merged
merged 1 commit into from
Aug 31, 2020

Conversation

JonasHelming
Copy link
Contributor

fixes: #8209
Signed-off-by: Jonas Helming jhelming@eclipsesource.com

What it does

It adds the capability to remove all keybindings for a specific command. also adds docu to the three available functions.

How to test

see included unit tests or unregister the keybindings of any command via API

Review checklist

Reminder for reviewers

@JonasHelming
Copy link
Contributor Author

This is based on the comment: #8209 (comment)

@JonasHelming
Copy link
Contributor Author

This is a duplicate of #8257 but with unit tests

@JonasHelming
Copy link
Contributor Author

No clue whats wron with the build, but I have the same failure on latest master

@akosyakov akosyakov added the keybindings issues related to keybindings label Aug 3, 2020
keybindingRegistry.unregisterKeybinding(TEST_COMMAND2);

const bindings = keybindingRegistry.getKeybindingsForCommand(TEST_COMMAND2.id);
if (bindings) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not expect? Same the other if.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really the thing we test here, but I will adapt that.


const bindings = keybindingRegistry.getKeybindingsForCommand(TEST_COMMAND2.id);
if (bindings) {
expect(bindings.length).to.be.equal(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add an expect before unregister.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I was expecting that there are test cases that validate the basic registration, but apparently there are none. I adapted that.

if (bindings) {
bindings.forEach(
(value: Keybinding) => {
expect(value.command === keybinding.command && value.keybinding === keybinding.keybinding).to.be.false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value.keybinding === keybinding.keybinding => #8170

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us fix that bug separatly, I can prepare a contribution


keybindingRegistry.registerKeybinding(keybinding);
keybindingRegistry.registerKeybinding(keybinding2);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an expect is missing here. These tests also pass if register/unregister does not work at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@JonasHelming
Copy link
Contributor Author

  • I extracted a function for the check that a keybinding is registered (much easier to read now)
  • I added the requested checks that a keybinding is registered before unregistering
  • I added one simple test case just for the registration
  • I removed the "number checks" cause every keybinding is checked specifically now

fixes: eclipse-theia#8209
Signed-off-by: Jonas Helming <jhelming@eclipsesource.com>
@JonasHelming
Copy link
Contributor Author

I resolved the conflicts

@@ -184,28 +184,36 @@ export class KeybindingRegistry {
}

/**
* Unregister keybinding from the registry
* Unregister keybindings from the registry using the key of the given keybinging
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo here: keybinging.

Copy link
Contributor

@kittaakos kittaakos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking care of this PR, @JonasHelming. Updated jsdocs, tests, convenient API 👍

@kittaakos kittaakos merged commit 10e16fe into eclipse-theia:master Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keybindings issues related to keybindings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[keybinding] As an extension developer I want to unregister keybindings by the command
3 participants