From 082918976ec2e8023ab21393f090ba0dd0b85fa7 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Mon, 25 Jun 2018 16:59:18 -0700 Subject: [PATCH] #52815 - Settings editor - 'enter' edits setting --- .../preferences/browser/settingsEditor2.ts | 28 +++++++++++++------ .../preferences.contribution.ts | 18 ++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/vs/workbench/parts/preferences/browser/settingsEditor2.ts b/src/vs/workbench/parts/preferences/browser/settingsEditor2.ts index 2975d4299b2..8726d796de5 100644 --- a/src/vs/workbench/parts/preferences/browser/settingsEditor2.ts +++ b/src/vs/workbench/parts/preferences/browser/settingsEditor2.ts @@ -155,6 +155,14 @@ export class SettingsEditor2 extends BaseEditor { this.searchWidget.focus(); } + editSelectedSetting(): void { + const focus = this.settingsTree.getFocus(); + if (focus instanceof SettingsTreeSettingElement) { + const itemId = focus.id.replace(/\./g, '_'); + this.focusEditControlForRow(itemId); + } + } + clearSearchResults(): void { this.searchWidget.clear(); } @@ -585,14 +593,7 @@ export class SettingsEditor2 extends BaseEditor { return this.settingsTree.refresh() .then(() => { if (focusedRowId) { - const rowSelector = `.setting-item#${focusedRowId}`; - const inputElementToFocus: HTMLElement = this.settingsTreeContainer.querySelector(`${rowSelector} input, ${rowSelector} select, ${rowSelector} a, ${rowSelector} .monaco-custom-checkbox`); - if (inputElementToFocus) { - inputElementToFocus.focus(); - if (typeof selection === 'number') { - (inputElementToFocus).setSelectionRange(selection, selection); - } - } + this.focusEditControlForRow(focusedRowId, selection); } }) .then(() => { @@ -600,6 +601,17 @@ export class SettingsEditor2 extends BaseEditor { }); } + private focusEditControlForRow(id: string, selection?: number): void { + const rowSelector = `.setting-item#${id}`; + const inputElementToFocus: HTMLElement = this.settingsTreeContainer.querySelector(`${rowSelector} input, ${rowSelector} select, ${rowSelector} a, ${rowSelector} .monaco-custom-checkbox`); + if (inputElementToFocus) { + inputElementToFocus.focus(); + if (typeof selection === 'number') { + (inputElementToFocus).setSelectionRange(selection, selection); + } + } + } + private onSearchInputChanged(): void { const query = this.searchWidget.getValue().trim(); this.delayedFilterLogging.cancel(); diff --git a/src/vs/workbench/parts/preferences/electron-browser/preferences.contribution.ts b/src/vs/workbench/parts/preferences/electron-browser/preferences.contribution.ts index 7c0c26e82a7..367346b7259 100644 --- a/src/vs/workbench/parts/preferences/electron-browser/preferences.contribution.ts +++ b/src/vs/workbench/parts/preferences/electron-browser/preferences.contribution.ts @@ -465,3 +465,21 @@ const editFocusedSettingCommand = new EditFocusedSettingCommand({ kbOpts: { primary: KeyMod.CtrlCmd | KeyCode.US_DOT } }); KeybindingsRegistry.registerCommandAndKeybindingRule(editFocusedSettingCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib())); + +class EditFocusedSettingCommand2 extends SettingsCommand { + + public runCommand(accessor: ServicesAccessor, args: any): void { + const preferencesEditor = this.getPreferencesEditor(accessor); + if (preferencesEditor instanceof SettingsEditor2) { + preferencesEditor.editSelectedSetting(); + } + } + +} + +const editFocusedSettingCommand2 = new EditFocusedSettingCommand2({ + id: SETTINGS_EDITOR_COMMAND_EDIT_FOCUSED_SETTING, + precondition: CONTEXT_SETTINGS_EDITOR, + kbOpts: { primary: KeyCode.Enter } +}); +KeybindingsRegistry.registerCommandAndKeybindingRule(editFocusedSettingCommand2.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.workbenchContrib())); -- GitLab