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

Add keybinding check in case when full and partial bindings are registered #6934

Merged
merged 1 commit into from
Jan 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 26 additions & 41 deletions packages/core/src/browser/keybinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ export class KeybindingRegistry {
matches.full.reverse();
matches.partial.reverse();
}
matches.full.forEach(binding => binding.scope = scope);
matches.partial.forEach(binding => binding.scope = scope);
result.merge(matches);
}
this.sortKeybindingsByPriority(result.full);
Expand Down Expand Up @@ -534,41 +536,27 @@ export class KeybindingRegistry {
/**
* Tries to execute a keybinding.
*
* @param bindings list of matching keybindings as returned by getKeybindingsForKeySequence.full
* @param binding to execute
* @param event keyboard event.
* @return true if the corresponding command was executed false otherwise.
*/
protected tryKeybindingExecution(bindings: Keybinding[], event: KeyboardEvent): boolean {

if (bindings.length === 0) {
return false;
}
protected executeKeyBinding(binding: Keybinding, event: KeyboardEvent): void {
if (this.isPseudoCommand(binding.command)) {
/* Don't do anything, let the event propagate. */
} else {
const command = this.commandRegistry.getCommand(binding.command);
if (command) {
const commandHandler = this.commandRegistry.getActiveHandler(command.id, binding.args);

for (const binding of bindings) {
if (this.isEnabled(binding, event)) {
if (this.isPseudoCommand(binding.command)) {
/* Don't do anything, let the event propagate. */
return true;
} else {
const command = this.commandRegistry.getCommand(binding.command);
if (command) {
const commandHandler = this.commandRegistry.getActiveHandler(command.id, binding.args);

if (commandHandler) {
commandHandler.execute(binding.args);
}

/* Note that if a keybinding is in context but the command is
not active we still stop the processing here. */
event.preventDefault();
event.stopPropagation();
return true;
}
if (commandHandler) {
commandHandler.execute(binding.args);
}
return false;

/* Note that if a keybinding is in context but the command is
not active we still stop the processing here. */
event.preventDefault();
event.stopPropagation();
}
}
return false;
}

/**
Expand Down Expand Up @@ -603,14 +591,9 @@ export class KeybindingRegistry {
this.keyboardLayoutService.validateKeyCode(keyCode);
this.keySequence.push(keyCode);
const bindings = this.getKeybindingsForKeySequence(this.keySequence);

if (bindings.partial.length === 0 && this.tryKeybindingExecution(bindings.full, event)) {

this.keySequence = [];
this.statusBar.removeElement('keybinding-status');

} else if (bindings.partial.some(binding => this.isEnabled(binding, event))) {

const full = bindings.full.find(binding => this.isEnabled(binding, event));
const partial = bindings.partial.find(binding => (!full || binding.scope! > full.scope!) && this.isEnabled(binding, event));
if (partial) {
/* Accumulate the keysequence */
event.preventDefault();
event.stopPropagation();
Expand All @@ -620,8 +603,10 @@ export class KeybindingRegistry {
alignment: StatusBarAlignment.LEFT,
priority: 2
});

} else {
if (full) {
this.executeKeyBinding(full, event);
}
this.keySequence = [];
this.statusBar.removeElement('keybinding-status');
}
Expand Down Expand Up @@ -669,9 +654,9 @@ export class KeybindingRegistry {

export namespace KeybindingRegistry {
export class KeybindingsResult {
full: Keybinding[] = [];
partial: Keybinding[] = [];
shadow: Keybinding[] = [];
full: ScopedKeybinding[] = [];
partial: ScopedKeybinding[] = [];
shadow: ScopedKeybinding[] = [];

/**
* Merge two results together inside `this`
Expand Down