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', {});