From d0265d67153afbfe70c1a11ad83d41e473580120 Mon Sep 17 00:00:00 2001 From: Samuel HULTGREN Date: Thu, 18 Feb 2021 17:40:49 +0100 Subject: [PATCH] Serialize the proper API object for the keymaps.json file Fixes issue #9087 Contributed by STMicroelectronics Signed-off-by: Samuel HULTGREN --- packages/core/src/common/keybinding.ts | 23 +++++++++++++------ .../keymaps/src/browser/keymaps-service.ts | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/core/src/common/keybinding.ts b/packages/core/src/common/keybinding.ts index 4895666178a29..c8e53e95d4e93 100644 --- a/packages/core/src/common/keybinding.ts +++ b/packages/core/src/common/keybinding.ts @@ -51,21 +51,30 @@ export interface Keybinding { 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. + * Returns a new object only containing properties which + * are described on the `Keybinding` API. * - * @param binding the binding to stringify. + * @param binding the binding to create an API object for. */ - export function stringify(binding: Keybinding): string { - const copy: Keybinding = { + export function apiObjectify(binding: Keybinding): Keybinding { + return { command: binding.command, keybinding: binding.keybinding, context: binding.context, when: binding.when, args: binding.args }; - return JSON.stringify(copy); + } + + /** + * 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 { + return JSON.stringify(apiObjectify(binding)); } /* Determine whether object is a KeyBinding */ diff --git a/packages/keymaps/src/browser/keymaps-service.ts b/packages/keymaps/src/browser/keymaps-service.ts index 2ba7d24434675..d50e65e78c5e8 100644 --- a/packages/keymaps/src/browser/keymaps-service.ts +++ b/packages/keymaps/src/browser/keymaps-service.ts @@ -189,7 +189,7 @@ export class KeymapsService { const textModel = model.textEditorModel; const { insertSpaces, tabSize, defaultEOL } = textModel.getOptions(); const editOperations: monaco.editor.IIdentifiedSingleEditOperation[] = []; - for (const edit of jsoncparser.modify(content, [], keybindings, { + for (const edit of jsoncparser.modify(content, [], keybindings.map(binding => Keybinding.apiObjectify(binding)), { formattingOptions: { insertSpaces, tabSize,