From 2dab3570b66283677c8c2e275e9467a67a11461e 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 Change-Id: I9c636c45654a028459247abc2d175c38bb9aaa58 Signed-off-by: Samuel HULTGREN --- packages/core/src/common/keybinding.ts | 18 ++++++++++-------- .../keymaps/src/browser/keymaps-service.ts | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/core/src/common/keybinding.ts b/packages/core/src/common/keybinding.ts index 4895666178a29..584e99f247c68 100644 --- a/packages/core/src/common/keybinding.ts +++ b/packages/core/src/common/keybinding.ts @@ -49,6 +49,15 @@ export interface Keybinding { args?: any; } export namespace Keybinding { + export function apiObjectify(binding: Keybinding): Keybinding { + return { + command: binding.command, + keybinding: binding.keybinding, + context: binding.context, + when: binding.when, + args: binding.args + }; + } /** * Returns with the string representation of the binding. @@ -58,14 +67,7 @@ export namespace Keybinding { * @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); + 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,