Skip to content

Commit

Permalink
fixup! Fixes for Vscode emacs extension
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Nov 26, 2019
1 parent dad0ff8 commit 6165a80
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
19 changes: 10 additions & 9 deletions packages/core/src/browser/keybinding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ describe('keybindings', () => {
expect(bindings.partial.length > 0);
});

it('should not register a shadowing keybinding', () => {
it('should register a shadowing keybinding', () => {
const validKeyBinding = 'ctrlcmd+b a';
const command = TEST_COMMAND_SHADOW.id;
const keybindingShadowing: Keybinding[] = [
Expand All @@ -270,22 +270,22 @@ describe('keybindings', () => {
keybindingRegistry.registerKeybindings(...keybindingShadowing);

const bindings = keybindingRegistry.getKeybindingsForCommand(command);
expect(bindings.length).to.be.equal(1);
expect(bindings.length).to.be.equal(2);
expect(bindings[0].keybinding).to.be.equal(validKeyBinding);
});

it('shadowed bindings should not be returned', () => {
it('shadowed bindings should also be returned', () => {
const keyCode = KeyCode.createKeyCode({ first: Key.KEY_A, modifiers: [KeyModifier.Shift] });
let bindings: Keybinding[];

const ignoredDefaultBinding: Keybinding = {
const defaultBinding: Keybinding = {
keybinding: keyCode.toString(),
command: 'test.ignored-command'
command: 'test.workspace-command'
};

const defaultBinding: Keybinding = {
const secondDefaultBinding: Keybinding = {
keybinding: keyCode.toString(),
command: 'test.workspace-command'
command: 'test.second-command'
};

const userBinding: Keybinding = {
Expand All @@ -298,7 +298,7 @@ describe('keybindings', () => {
command: 'test.workspace-command'
};

keybindingRegistry.setKeymap(KeybindingScope.DEFAULT, [defaultBinding, ignoredDefaultBinding]);
keybindingRegistry.setKeymap(KeybindingScope.DEFAULT, [defaultBinding, secondDefaultBinding]);
keybindingRegistry.setKeymap(KeybindingScope.USER, [userBinding]);
keybindingRegistry.setKeymap(KeybindingScope.WORKSPACE, [workspaceBinding]);
// now WORKSPACE bindings are overriding the other scopes
Expand All @@ -318,8 +318,9 @@ describe('keybindings', () => {
// and finally it should fallback to DEFAULT bindings.

bindings = keybindingRegistry.getKeybindingsForKeySequence([keyCode]).full;
expect(bindings).to.have.lengthOf(1);
expect(bindings).to.have.lengthOf(2);
expect(bindings[0].command).to.be.equal(defaultBinding.command);
expect(bindings[1].command).to.be.equal(secondDefaultBinding.command);

keybindingRegistry.resetKeybindingsForScope(KeybindingScope.DEFAULT);
// now the registry should be empty
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/browser/keybinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class KeybindingRegistry {
protected doRegisterKeybinding(binding: Keybinding, scope: KeybindingScope = KeybindingScope.DEFAULT): Disposable {
try {
this.resolveKeybinding(binding);
this.checkKeybindingCollisions(this.keymaps[scope], binding);
this.containsKeybinding(this.keymaps[scope], binding);
this.keymaps[scope].push(binding);
return Disposable.create(() => {
const index = this.keymaps[scope].indexOf(binding);
Expand Down Expand Up @@ -286,7 +286,7 @@ export class KeybindingRegistry {
* @param bindings the keybinding reference list
* @param binding the keybinding to test collisions for
*/
checkKeybindingCollisions(bindings: Keybinding[], binding: Keybinding): boolean {
containsKeybinding(bindings: Keybinding[], binding: Keybinding): boolean {
const bindingKeySequence = this.resolveKeybinding(binding);
const collisions = this.getKeySequenceCollisions(bindings, bindingKeySequence)
.filter(b => b.context === binding.context && !b.when && !binding.when);
Expand All @@ -313,7 +313,7 @@ export class KeybindingRegistry {
}

containsKeybindingInScope(binding: Keybinding, scope = KeybindingScope.USER): boolean {
return this.checkKeybindingCollisions(this.keymaps[scope], binding);
return this.containsKeybinding(this.keymaps[scope], binding);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,9 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
commands.registerCommand({ id: 'undo' }, {
execute: () => commands.executeCommand(CommonCommands.UNDO.id)
});
commands.registerCommand({ id: 'workbench.action.quickOpen' }, {
execute: () => commands.executeCommand(CommonCommands.UNDO.id)
});
commands.registerCommand({ id: 'workbench.action.closeAllEditors' }, {
execute: () => commands.executeCommand(CommonCommands.CLOSE_ALL_TABS.id)
});

commands.registerCommand({ id: 'workbench.action.quickOpen' }, {
execute: () => this.quickOpen.open('')
});
Expand Down

0 comments on commit 6165a80

Please sign in to comment.