提交 1fa8bcdf 编写于 作者: J Johannes Rieken

add `editor.acceptSuggestionOnEnter` option to control iff Enter accepts a...

add `editor.acceptSuggestionOnEnter` option to control iff Enter accepts a suggestion or inserts a new line, fixes #1657
上级 576824d7
......@@ -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,
......@@ -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),
......@@ -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,
......
......@@ -72,6 +72,7 @@ class ConfigClass implements IConfiguration {
autoClosingBrackets: true,
formatOnType: false,
suggestOnTriggerCharacters: true,
acceptSuggestionOnEnter: true,
selectionHighlight: true,
outlineMarkers: false,
referenceInfos: true,
......
......@@ -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.
......@@ -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;
......
......@@ -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';
......@@ -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';
......@@ -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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册