Skip to content

Commit

Permalink
Serialize the proper API object for the keymaps.json file
Browse files Browse the repository at this point in the history
Fixes issue #9087

Contributed by STMicroelectronics
Signed-off-by: Samuel HULTGREN <samuel.hultgren@st.com>
  • Loading branch information
slhultgren authored and kittaakos committed Feb 24, 2021
1 parent c5f3253 commit d0265d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions packages/core/src/common/keybinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion packages/keymaps/src/browser/keymaps-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d0265d6

Please sign in to comment.