Skip to content

Commit

Permalink
[keybinding] fix #6878: allow a user to change default keybindings
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Jan 15, 2020
1 parent f11045a commit ea5fd09
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 446 deletions.
26 changes: 1 addition & 25 deletions packages/core/src/browser/keybinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,11 @@ export namespace KeybindingScope {
export const length = KeybindingScope.END - KeybindingScope.DEFAULT;
}

export namespace Keybinding {

/**
* Returns with the string representation of the binding.
* Any additional properties which are not described on
* the `Keybinding` API will be ignored.
*
* @param binding the binding to stringify.
*/
export function stringify(binding: Keybinding): string {
const copy: Keybinding = {
command: binding.command,
keybinding: binding.keybinding,
context: binding.context
};
return JSON.stringify(copy);
}

/* Determine whether object is a KeyBinding */
// tslint:disable-next-line:no-any
export function is(arg: Keybinding | any): arg is Keybinding {
return !!arg && arg === Object(arg) && 'command' in arg && 'keybinding' in arg;
}
}

/**
* @deprecated import from `@theia/core/lib/common/keybinding` instead
*/
export type Keybinding = common.Keybinding;
export const Keybinding = common.Keybinding;

export interface ResolvedKeybinding extends Keybinding {
/**
Expand Down
26 changes: 26 additions & 0 deletions packages/core/src/common/keybinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,29 @@ export interface Keybinding {
// tslint:disable-next-line no-any
args?: any;
}
export namespace Keybinding {

/**
* Returns with the string representation of the binding.
* Any additional properties which are not described on
* the `Keybinding` API will be ignored.
*
* @param binding the binding to stringify.
*/
export function stringify(binding: Keybinding): string {
const copy: Keybinding = {
command: binding.command,
keybinding: binding.keybinding,
context: binding.context,
when: binding.when,
args: binding.args
};
return JSON.stringify(copy);
}

/* Determine whether object is a KeyBinding */
// tslint:disable-next-line:no-any
export function is(arg: Keybinding | any): arg is Keybinding {
return !!arg && arg === Object(arg) && 'command' in arg && 'keybinding' in arg;
}
}
Loading

0 comments on commit ea5fd09

Please sign in to comment.