Skip to content

Commit

Permalink
add editor.acceptSuggestionOnEnter option to control iff Enter acce…
Browse files Browse the repository at this point in the history
…pts a suggestion or inserts a new line, fixes #1657
  • Loading branch information
jrieken committed Mar 9, 2016
1 parent 576824d commit 1fa8bcd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/vs/editor/common/config/commonEditorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ function cloneInternalEditorOptions(opts: editorCommon.IInternalEditorOptions):
autoClosingBrackets: opts.autoClosingBrackets,
formatOnType: opts.formatOnType,
suggestOnTriggerCharacters: opts.suggestOnTriggerCharacters,
acceptSuggestionOnEnter: opts.acceptSuggestionOnEnter,
selectionHighlight: opts.selectionHighlight,
outlineMarkers: opts.outlineMarkers,
referenceInfos: opts.referenceInfos,
Expand Down Expand Up @@ -298,6 +299,7 @@ class InternalEditorOptionsHelper {
autoClosingBrackets: toBoolean(opts.autoClosingBrackets),
formatOnType: toBoolean(opts.formatOnType),
suggestOnTriggerCharacters: toBoolean(opts.suggestOnTriggerCharacters),
acceptSuggestionOnEnter: toBoolean(opts.acceptSuggestionOnEnter),
selectionHighlight: toBoolean(opts.selectionHighlight),
outlineMarkers: toBoolean(opts.outlineMarkers),
referenceInfos: toBoolean(opts.referenceInfos),
Expand Down Expand Up @@ -815,6 +817,11 @@ configurationRegistry.registerConfiguration({
'default': DefaultConfig.editor.suggestOnTriggerCharacters,
'description': nls.localize('suggestOnTriggerCharacters', "Controls if suggestions should automatically show up when typing trigger characters")
},
'editor.acceptSuggestionOnEnter' : {
'type': 'boolean',
'default': DefaultConfig.editor.acceptSuggestionOnEnter,
'description': nls.localize('acceptSuggestionOnEnter', "Controls if suggestions should be accepted 'Enter' - in addition to 'Tab'. Helps to avoid ambiguity between inserting new lines or accepting suggestions.")
},
'editor.selectionHighlight' : {
'type': 'boolean',
'default': DefaultConfig.editor.selectionHighlight,
Expand Down
1 change: 1 addition & 0 deletions src/vs/editor/common/config/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ConfigClass implements IConfiguration {
autoClosingBrackets: true,
formatOnType: false,
suggestOnTriggerCharacters: true,
acceptSuggestionOnEnter: true,
selectionHighlight: true,
outlineMarkers: false,
referenceInfos: true,
Expand Down
10 changes: 8 additions & 2 deletions src/vs/editor/common/editorCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,12 @@ export interface IEditorOptions {
* Enable the suggestion box to pop-up on trigger characters.
* Defaults to true.
*/
suggestOnTriggerCharacters?:boolean;
suggestOnTriggerCharacters?: boolean;
/**
* Accept suggestions on ENTER.
* Defaults to true.
*/
acceptSuggestionOnEnter?: boolean;
/**
* Enable selection highlight.
* Defaults to true.
Expand Down Expand Up @@ -620,7 +625,8 @@ export interface IInternalEditorOptions {
iconsInSuggestions:boolean;
autoClosingBrackets:boolean;
formatOnType:boolean;
suggestOnTriggerCharacters:boolean;
suggestOnTriggerCharacters: boolean;
acceptSuggestionOnEnter: boolean;
selectionHighlight:boolean;
outlineMarkers: boolean;
referenceInfos: boolean;
Expand Down
18 changes: 16 additions & 2 deletions src/vs/editor/contrib/suggest/browser/suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {KeyCode, KeyMod} from 'vs/base/common/keyCodes';
import {IDisposable, cAll, disposeAll} from 'vs/base/common/lifecycle';
import {TPromise} from 'vs/base/common/winjs.base';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IKeybindingContextKey, IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {IKeybindingContextKey, IKeybindingService, KbExpr} from 'vs/platform/keybinding/common/keybindingService';
import {EditorAction} from 'vs/editor/common/editorAction';
import {EventType, ICommonCodeEditor, IEditorActionDescriptorData, IEditorContribution, IModeSupportChangedEvent} from 'vs/editor/common/editorCommon';
import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
Expand All @@ -19,6 +19,8 @@ import {ICodeEditor} from 'vs/editor/browser/editorBrowser';
import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions';
import {getSnippetController} from 'vs/editor/contrib/snippet/common/snippet';
import {ACCEPT_SELECTED_SUGGESTION_CMD, CONTEXT_SUGGEST_WIDGET_VISIBLE, SuggestRegistry} from 'vs/editor/contrib/suggest/common/suggest';
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import {withCodeEditorFromCommandHandler} from 'vs/editor/common/config/config';
import {SuggestModel} from './suggestModel';
import {SuggestWidget} from './suggestWidget';

Expand Down Expand Up @@ -219,10 +221,22 @@ CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(TriggerSugg
primary: KeyMod.CtrlCmd | KeyCode.Space,
mac: { primary: KeyMod.WinCtrl | KeyCode.Space }
}));
CommonEditorRegistry.registerEditorCommand(ACCEPT_SELECTED_SUGGESTION_CMD, weight, { primary: KeyCode.Enter, secondary: [KeyCode.Tab] }, true, CONTEXT_SUGGEST_WIDGET_VISIBLE, (ctx, editor, args) => {
CommonEditorRegistry.registerEditorCommand(ACCEPT_SELECTED_SUGGESTION_CMD, weight, { primary: KeyCode.Tab }, true, CONTEXT_SUGGEST_WIDGET_VISIBLE, (ctx, editor, args) => {
const controller = SuggestController.getSuggestController(editor);
controller.acceptSelectedSuggestion();
});
KeybindingsRegistry.registerCommandDesc({
id: ACCEPT_SELECTED_SUGGESTION_CMD,
handler(accessor, args) {
withCodeEditorFromCommandHandler(ACCEPT_SELECTED_SUGGESTION_CMD, accessor, args, (editor) => {
const controller = SuggestController.getSuggestController(editor);
controller.acceptSelectedSuggestion();
});
},
weight,
context: KbExpr.and(KbExpr.has(CONTEXT_SUGGEST_WIDGET_VISIBLE), KbExpr.has('config.editor.acceptSuggestionOnEnter')),
primary: KeyCode.Enter,
});
CommonEditorRegistry.registerEditorCommand('hideSuggestWidget', weight, { primary: KeyCode.Escape }, true, CONTEXT_SUGGEST_WIDGET_VISIBLE, (ctx, editor, args) => {
const controller = SuggestController.getSuggestController(editor);
controller.cancelSuggestWidget();
Expand Down

0 comments on commit 1fa8bcd

Please sign in to comment.