diff --git a/src/vs/platform/keybinding/common/abstractKeybindingService.ts b/src/vs/platform/keybinding/common/abstractKeybindingService.ts index 79157f0cc91e82868aeea9403cc33becd12ec094..176a15f5e276bd7d7c0544584c29cc0f397348bd 100644 --- a/src/vs/platform/keybinding/common/abstractKeybindingService.ts +++ b/src/vs/platform/keybinding/common/abstractKeybindingService.ts @@ -66,10 +66,14 @@ export abstract class AbstractKeybindingService implements IKeybindingService { public abstract resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding; public abstract resolveUserBinding(userBinding: string): ResolvedKeybinding[]; - public getDefaultKeybindings(): string { + public getDefaultKeybindingsContent(): string { return ''; } + public getDefaultKeybindings(): ResolvedKeybindingItem[] { + return this._getResolver().getDefaultKeybindings(); + } + public getKeybindings(): ResolvedKeybindingItem[] { return this._getResolver().getKeybindings(); } diff --git a/src/vs/platform/keybinding/common/keybinding.ts b/src/vs/platform/keybinding/common/keybinding.ts index c68e53772fa5d883e71e7a10954fe492e76ff5c3..e2bef743f6da2f1d903abf6f28d421031a523fa8 100644 --- a/src/vs/platform/keybinding/common/keybinding.ts +++ b/src/vs/platform/keybinding/common/keybinding.ts @@ -70,7 +70,9 @@ export interface IKeybindingService { */ lookupKeybinding(commandId: string): ResolvedKeybinding; - getDefaultKeybindings(): string; + getDefaultKeybindingsContent(): string; + + getDefaultKeybindings(): ResolvedKeybindingItem[]; getKeybindings(): ResolvedKeybindingItem[]; diff --git a/src/vs/platform/keybinding/test/common/mockKeybindingService.ts b/src/vs/platform/keybinding/test/common/mockKeybindingService.ts index 1a30636939d1cb8f2be1c5302d000c7cb9ef930f..4c4e03c566ca4cb6d6ba38d4d9c060fc116a11d8 100644 --- a/src/vs/platform/keybinding/test/common/mockKeybindingService.ts +++ b/src/vs/platform/keybinding/test/common/mockKeybindingService.ts @@ -69,10 +69,14 @@ export class MockKeybindingService implements IKeybindingService { return Event.None; } - public getDefaultKeybindings(): string { + public getDefaultKeybindingsContent(): string { return null; } + public getDefaultKeybindings(): ResolvedKeybindingItem[] { + return []; + } + public getKeybindings(): ResolvedKeybindingItem[] { return []; } diff --git a/src/vs/workbench/parts/preferences/browser/keybindingsEditor.ts b/src/vs/workbench/parts/preferences/browser/keybindingsEditor.ts index 5a89694880c225a82710cc75c1440b1e51c6d570..0120f504757a7f1954fe2e06a9db5e0eb19addb1 100644 --- a/src/vs/workbench/parts/preferences/browser/keybindingsEditor.ts +++ b/src/vs/workbench/parts/preferences/browser/keybindingsEditor.ts @@ -66,6 +66,9 @@ export class KeybindingsEditorInput extends EditorInput { export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor { public static ID: string = 'workbench.editor.keybindings'; + + private keybindingsEditorModel: KeybindingsEditorModel; + private headerContainer: HTMLElement; private searchWidget: SearchWidget; @@ -199,15 +202,17 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor resetKeybinding(keybindingEntry: IKeybindingItemEntry): TPromise { this.selectEntry(keybindingEntry); - if (keybindingEntry.keybindingItem.keybinding) { // This should be a pre-condition - return this.keybindingEditingService.resetKeybinding(keybindingEntry.keybindingItem.keybindingItem) - .then(() => this.focus(), - error => { - this.onKeybindingEditingError(error); - this.selectEntry(keybindingEntry); - }); - } - return TPromise.as(null); + return this.keybindingEditingService.resetKeybinding(keybindingEntry.keybindingItem.keybindingItem) + .then(() => { + if (!keybindingEntry.keybindingItem.keybinding) { // reveal only if keybinding was added to unassinged. Because the entry will be placed in different position after rendering + this.unAssignedKeybindingItemToRevealAndFocus = keybindingEntry; + } + this.selectEntry(keybindingEntry); + }, + error => { + this.onKeybindingEditingError(error); + this.selectEntry(keybindingEntry); + }); } copyKeybinding(keybinding: IKeybindingItemEntry): TPromise { @@ -250,7 +255,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor placeholder: localize('SearchKeybindings.Placeholder', "Search keybindings"), navigateByArrows: true })); - this._register(this.searchWidget.onDidChange(searchValue => this.delayedFiltering.trigger(() => this.render()))); + this._register(this.searchWidget.onDidChange(searchValue => this.delayedFiltering.trigger(() => this.renderKeybindingsEntries()))); this._register(this.searchWidget.onNavigate(back => this._onNavigate(back))); this.createOpenKeybindingsElement(this.headerContainer); @@ -295,27 +300,31 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor private render(): TPromise { if (this.input) { return this.input.resolve() - .then((keybindingsModel: KeybindingsEditorModel) => keybindingsModel.resolve() - .then(() => this.renderKeybindingsEntries(keybindingsModel.fetch(this.searchWidget.value())))); + .then((keybindingsModel: KeybindingsEditorModel) => this.keybindingsEditorModel = keybindingsModel) + .then(() => this.keybindingsEditorModel.resolve()) + .then(() => this.renderKeybindingsEntries()); } return TPromise.as(null); } - private renderKeybindingsEntries(keybindingsEntries: IKeybindingItemEntry[]): void { - const currentSelectedIndex = this.keybindingsList.getSelection()[0]; - this.listEntries = [{ id: 'keybinding-header-entry', templateId: KEYBINDING_HEADER_TEMPLATE_ID }, ...keybindingsEntries]; - this.keybindingsList.splice(0, this.keybindingsList.length, this.listEntries); - this.layoutKebindingsList(); + private renderKeybindingsEntries(): void { + if (this.keybindingsEditorModel) { + const keybindingsEntries: IKeybindingItemEntry[] = this.keybindingsEditorModel.fetch(this.searchWidget.value()); + const currentSelectedIndex = this.keybindingsList.getSelection()[0]; + this.listEntries = [{ id: 'keybinding-header-entry', templateId: KEYBINDING_HEADER_TEMPLATE_ID }, ...keybindingsEntries]; + this.keybindingsList.splice(0, this.keybindingsList.length, this.listEntries); + this.layoutKebindingsList(); - if (this.unAssignedKeybindingItemToRevealAndFocus) { - const index = this.getNewIndexOfUnassignedKeybinding(this.unAssignedKeybindingItemToRevealAndFocus); - if (index !== -1) { - this.keybindingsList.reveal(index, 0.2); - this.selectEntry(index); + if (this.unAssignedKeybindingItemToRevealAndFocus) { + const index = this.getNewIndexOfUnassignedKeybinding(this.unAssignedKeybindingItemToRevealAndFocus); + if (index !== -1) { + this.keybindingsList.reveal(index, 0.2); + this.selectEntry(index); + } + this.unAssignedKeybindingItemToRevealAndFocus = null; + } else if (currentSelectedIndex !== -1 && currentSelectedIndex < this.listEntries.length) { + this.selectEntry(currentSelectedIndex); } - this.unAssignedKeybindingItemToRevealAndFocus = null; - } else if (currentSelectedIndex !== -1 && currentSelectedIndex < this.listEntries.length) { - this.selectEntry(currentSelectedIndex); } } @@ -405,7 +414,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor private createResetAction(keybindingItem: IKeybindingItemEntry): IAction { return { label: localize('resetLabel', "Reset Keybinding"), - enabled: !!keybindingItem.keybindingItem.keybinding && !keybindingItem.keybindingItem.keybindingItem.isDefault, + enabled: !keybindingItem.keybindingItem.keybindingItem.isDefault, id: KEYBINDINGS_EDITOR_COMMAND_RESET, run: () => this.resetKeybinding(keybindingItem) }; diff --git a/src/vs/workbench/parts/preferences/browser/media/keybindingsEditor.css b/src/vs/workbench/parts/preferences/browser/media/keybindingsEditor.css index b7b19ac7ccef45875c98a2be6d53a2b8b8cf4a5f..38875c65054a5b52cdd4d533fd9d17750b22e7fe 100644 --- a/src/vs/workbench/parts/preferences/browser/media/keybindingsEditor.css +++ b/src/vs/workbench/parts/preferences/browser/media/keybindingsEditor.css @@ -67,7 +67,8 @@ } .keybindings-editor > .keybindings-body > .keybindings-list-container .monaco-list-row.keybindings-list-header, -.keybindings-editor > .keybindings-body > .keybindings-list-container .monaco-list-row.even:not(.focused):not(.selected):not(:hover) { +.keybindings-editor > .keybindings-body > .keybindings-list-container .monaco-list-row.even:not(.focused):not(.selected):not(:hover), +.keybindings-editor > .keybindings-body > .keybindings-list-container .monaco-list:not(:focus) .monaco-list-row.focused.even:not(.selected):not(:hover) { background-color: rgba(130, 130, 130, 0.04); } diff --git a/src/vs/workbench/parts/preferences/common/keybindingsEditorModel.ts b/src/vs/workbench/parts/preferences/common/keybindingsEditorModel.ts index b80e5be194df8b0e0c1a44515ec4585ded5d59f0..fd86cfded4b06cfeb77a1bab3afa0ec2843b0343 100644 --- a/src/vs/workbench/parts/preferences/common/keybindingsEditorModel.ts +++ b/src/vs/workbench/parts/preferences/common/keybindingsEditorModel.ts @@ -110,8 +110,10 @@ export class KeybindingsEditorModel extends EditorModel { } } + const commandsWithDefaultKeybindings = this.keybindingsService.getDefaultKeybindings().map(keybinding => keybinding.command); for (const command of KeybindingResolver.getAllUnboundCommands(boundCommands)) { - this._keybindingItems.push(KeybindingsEditorModel.toKeybindingEntry(command, null, workbenchActionsRegistry, editorActions)); + const keybindingItem = new ResolvedKeybindingItem(null, command, null, null, commandsWithDefaultKeybindings.indexOf(command) === -1); + this._keybindingItems.push(KeybindingsEditorModel.toKeybindingEntry(command, keybindingItem, workbenchActionsRegistry, editorActions)); } this._keybindingItems = this._keybindingItems.sort((a, b) => KeybindingsEditorModel.compareKeybindingData(a, b)); return this; @@ -150,7 +152,6 @@ export class KeybindingsEditorModel extends EditorModel { const workbenchAction = workbenchActionsRegistry.getWorkbenchAction(command); const menuCommand = MenuRegistry.getCommand(command); const editorAction: EditorAction = editorActions[command]; - keybindingItem = keybindingItem ? keybindingItem : new ResolvedKeybindingItem(null, command, null, null, true); return { keybinding: keybindingItem.resolvedKeybinding, keybindingItem, diff --git a/src/vs/workbench/parts/preferences/common/preferencesModels.ts b/src/vs/workbench/parts/preferences/common/preferencesModels.ts index 1aa1b5c9627a6bd6591ac860fed37b90432dcc8e..2f8b65ebaeeb5f409bb2baa41f611f6b93df21fb 100644 --- a/src/vs/workbench/parts/preferences/common/preferencesModels.ts +++ b/src/vs/workbench/parts/preferences/common/preferencesModels.ts @@ -706,7 +706,7 @@ export class DefaultKeybindingsEditorModel implements IKeybindingsEditorModel