MonacoEditor是微软提供的代码编辑器浏览器
vscode便是使用它做为编辑器。编辑器
它的开发语言是ts,能够嵌入到浏览器中。ide
代码提示或者说代码补全功能是咱们常常须要定制的部分。this
目前它提供的快捷键是ctrl+space,和win10如下的操做系统的默认中英文切换是冲突的。spa
检查源码发现,TriggerSuggestAction的触发快捷键已经写死:操作系统
function TriggerSuggestAction() { return _super.call(this, { id: 'editor.action.triggerSuggest', label: nls.localize(0, null), alias: 'Trigger Suggest', precondition: contextkey_1.ContextKeyExpr.and(editorCommon_1.EditorContextKeys.Writable, editorCommon_1.ModeContextKeys.hasCompletionItemProvider), kbOpts: { kbExpr: editorCommon_1.EditorContextKeys.TextFocus, primary: 2048 /* CtrlCmd */ | 10 /* Space */, mac: { primary: 256 /* WinCtrl */ | 10 /* Space */ } } }) || this; }
既然无法改快捷键,它的run方法实现以下:prototype
TriggerSuggestAction.prototype.run = function (accessor, editor) { SuggestController.get(editor).triggerSuggest(); };
便是说,只要有办法调用这个triggerSuggest便可,可是SuggestControll而是个私有对象,要如何调用呢?code
继续看源码:对象
SuggestController.get = function (editor) { return editor.getContribution(SuggestController_1.ID); }; SuggestController.prototype.getId = function () { return SuggestController_1.ID; }; SuggestController.ID = 'editor.contrib.suggestController'; SuggestController = SuggestController_1
能够得出结论blog
editor.getContribution('editor.contrib.suggestController').triggerSuggest
这个就是咱们所须要的调用代码。
固然,还有一种更推荐的形式:
editor.trigger('随便写点儿啥', 'editor.action.triggerSuggest', {});