UNPKG

alm

Version:

The best IDE for TypeScript

71 lines (70 loc) 2.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var utils = require("../common/utils"); var commands = require("./commands/commands"); var appTabsContainer_1 = require("./tabs/v2/appTabsContainer"); var docCache = require("./monaco/model/docCache"); /** * After the app boots up */ function setup() { /** * Setup all the CM commands to go to the right place */ commands.commandRegistry .filter(function (x) { return x.config.context == commands.CommandContext.Editor; }) .forEach(function (cmd) { cmd.on(function () { var editorTab = API.getFocusedCodeEditorIfAny(); if (editorTab && editorTab.editor) { var editor = editorTab.editor; var action_1 = editor.getAction(cmd.config.editorCommandName); if (!action_1) { console.error('Failed to find editor action:', cmd.config); } else { // We need a set timeout as when we trigger from 'command search' the focus changes throws off monaco // e.g. goto line action (which tries to create its own modal) does not work without the set timeout setTimeout(function () { // console.log(action); // DEBUG action details action_1.run(); }); } } }); }); } exports.setup = setup; /** * Functions that can be provided as API */ var API; (function (API) { function getClosedVsOpenFilePaths(filePaths) { /** lookup all the *file* tabs that are open */ var allOpen = appTabsContainer_1.tabState.getOpenFilePaths(); var alreadyOpenFilePaths = filePaths.filter(function (fp) { return allOpen.indexOf(fp) != -1; }); var currentlyClosedFilePaths = filePaths.filter(function (fp) { return allOpen.indexOf(fp) == -1; }); return { alreadyOpenFilePaths: alreadyOpenFilePaths, currentlyClosedFilePaths: currentlyClosedFilePaths }; } API.getClosedVsOpenFilePaths = getClosedVsOpenFilePaths; function applyRefactorings(refactorings) { var currentlyClosedFilePaths = getClosedVsOpenFilePaths(Object.keys(refactorings)).currentlyClosedFilePaths; var tabs = currentlyClosedFilePaths.map(function (fp) { var codeTab = { id: utils.createId(), url: "file://" + fp, additionalData: null }; return codeTab; }); appTabsContainer_1.tabState.addTabs(tabs); // Transact on docs docCache.applyRefactoringsToTsDocs(refactorings); } API.applyRefactorings = applyRefactorings; function getFocusedCodeEditorIfAny() { return appTabsContainer_1.tabState.getFocusedCodeEditorIfAny(); } API.getFocusedCodeEditorIfAny = getFocusedCodeEditorIfAny; })(API = exports.API || (exports.API = {}));