Skip to content

Commit

Permalink
Add keybinding check in case when full and partial bindings are regis…
Browse files Browse the repository at this point in the history
…tered

Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
  • Loading branch information
vinokurig committed Jan 21, 2020
1 parent e9449a0 commit 7b80601
Showing 1 changed file with 25 additions and 36 deletions.
61 changes: 25 additions & 36 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,15 @@ 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)) {
const full = bindings.full.find(binding => this.isEnabled(binding, event));
const partial = bindings.partial.find(binding => this.isEnabled(binding, event));
if (full && full.scope !== undefined && partial && partial.scope !== undefined && full.scope >= partial.scope || full && !partial) {

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

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

this.executeKeyBinding(full, event);
} else if (partial !== undefined) {
/* Accumulate the keysequence */
event.preventDefault();
event.stopPropagation();
Expand Down Expand Up @@ -669,9 +658,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

0 comments on commit 7b80601

Please sign in to comment.