diff --git a/src/vs/platform/keybinding/common/keybindingResolver.ts b/src/vs/platform/keybinding/common/keybindingResolver.ts index b88d37524e2431ce20b0b5f8d35296b9738d2e6e..d1c777bf7b0a234c9265dc772da1af4526751d84 100644 --- a/src/vs/platform/keybinding/common/keybindingResolver.ts +++ b/src/vs/platform/keybinding/common/keybindingResolver.ts @@ -408,11 +408,24 @@ export class IOSupport { } public static readKeybindingItem(input: IUserFriendlyKeybinding, index: number): IKeybindingItem { - let key = IOSupport.readKeybinding(input.key); - let when = IOSupport.readKeybindingWhen(input.when); + let key:number = 0; + if (typeof input.key === 'string') { + key = IOSupport.readKeybinding(input.key); + } + + let when:ContextKeyExpr = null; + if (typeof input.when === 'string') { + when = IOSupport.readKeybindingWhen(input.when); + } + + let command:string = null; + if (typeof input.command === 'string') { + command = input.command; + } + return { keybinding: key, - command: input.command, + command: command, when: when, weight1: 1000, weight2: index diff --git a/src/vs/platform/keybinding/test/common/keybindingIO.test.ts b/src/vs/platform/keybinding/test/common/keybindingIO.test.ts index 1962a7a997e473643fa8366b96c8babe64e2b6d6..d8058e1f9dd9155c3bb32f497a8b1fe19a81c679 100644 --- a/src/vs/platform/keybinding/test/common/keybindingIO.test.ts +++ b/src/vs/platform/keybinding/test/common/keybindingIO.test.ts @@ -6,7 +6,8 @@ import * as assert from 'assert'; import {ISimplifiedPlatform, KeyCode, KeyMod} from 'vs/base/common/keyCodes'; -import {IOSupport} from 'vs/platform/keybinding/common/keybindingResolver'; +import {NormalizedKeybindingItem, IOSupport} from 'vs/platform/keybinding/common/keybindingResolver'; +import {IUserFriendlyKeybinding} from 'vs/platform/keybinding/common/keybinding'; suite('Keybinding IO', () => { @@ -110,4 +111,28 @@ suite('Keybinding IO', () => { testDeserialization(' ctrl-shift-alt-win-A ', ' shift-alt-cmd-Ctrl-A ', ' ctrl-shift-alt-META-A ', KeyMod.CtrlCmd | KeyMod.Shift | KeyMod.Alt | KeyMod.WinCtrl | KeyCode.KEY_A); }); -}); \ No newline at end of file + + test('issue #10452 - invalid command', () => { + let strJSON = `[{ "key": "ctrl+k ctrl+f", "command": ["firstcommand", "seccondcommand"] }]`; + let userKeybinding = JSON.parse(strJSON)[0]; + let keybindingItem = IOSupport.readKeybindingItem(userKeybinding, 0); + let normalizedKeybindingItem = NormalizedKeybindingItem.fromKeybindingItem(keybindingItem, false); + assert.equal(normalizedKeybindingItem.command, null); + }); + + test('issue #10452 - invalid when', () => { + let strJSON = `[{ "key": "ctrl+k ctrl+f", "command": "firstcommand", "when": [] }]`; + let userKeybinding = JSON.parse(strJSON)[0]; + let keybindingItem = IOSupport.readKeybindingItem(userKeybinding, 0); + let normalizedKeybindingItem = NormalizedKeybindingItem.fromKeybindingItem(keybindingItem, false); + assert.equal(normalizedKeybindingItem.when, null); + }); + + test('issue #10452 - invalid key', () => { + let strJSON = `[{ "key": [], "command": "firstcommand" }]`; + let userKeybinding = JSON.parse(strJSON)[0]; + let keybindingItem = IOSupport.readKeybindingItem(userKeybinding, 0); + let normalizedKeybindingItem = NormalizedKeybindingItem.fromKeybindingItem(keybindingItem, false); + assert.equal(normalizedKeybindingItem.keybinding, 0); + }); +});