UNPKG

alm

Version:

The best IDE for TypeScript

45 lines (44 loc) 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Note: a lot of the *on enter* docblocking is done by the `richLanguageConfiguration` `onEnterRules`. * * Here we mostly only implement the `snippets` */ var events_1 = require("../../../common/events"); /** * Note: the order of the snippets is important */ var snippets = { '////': "//////////////////////\n// {{}}\n//////////////////////", '///': "/**\n * {{}}\n */", '//': "/** {{}} */", }; function setup(editor) { // if (editor) return { dispose: () => null }; // DEBUG : while the feature isn't complete used to disable it var disposible = new events_1.CompositeDisposible(); disposible.add(editor.onKeyDown(function (e) { if (e.keyCode === monaco.KeyCode.Tab) { var position = editor.getPosition(); var contents = editor.getModel().getLineContent(position.lineNumber).substr(0, position.column - 1); var matchers = Object.keys(snippets); for (var _i = 0, matchers_1 = matchers; _i < matchers_1.length; _i++) { var snippetKey = matchers_1[_i]; if (contents.endsWith(snippetKey)) { e.preventDefault(); e.stopPropagation(); /** Insert the snippet */ var codeSnippet = monaco.CodeSnippet.fromInternal(snippets[snippetKey]); var overwriteBefore = snippetKey.length; var overwriteAfter = 0; monaco.SnippetController.get(editor).run(codeSnippet, overwriteBefore, overwriteAfter, true); // Don't run any other snippets :) return; } } } return; })); return disposible; } exports.setup = setup;