alm
Version:
The best IDE for TypeScript
554 lines (553 loc) • 17 kB
JavaScript
"use strict";
/**
* Defines:
* commands / command registry / code editor commands
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
// Keyboard shortcut origins:
// c9: cloud9 IDE
// ca: CodeAnywhere
// atom: github atom
// sublime: sublime text
// code: VScode
//---------------------------------------------
//
// This file also sets up Monaco keybindings
var Mousetrap = require("mousetrap");
require("mousetrap/plugins/global-bind/mousetrap-global-bind");
var events = require("../../common/events");
var CommandContext;
(function (CommandContext) {
CommandContext[CommandContext["Global"] = 0] = "Global";
CommandContext[CommandContext["Editor"] = 1] = "Editor";
CommandContext[CommandContext["TreeView"] = 2] = "TreeView";
})(CommandContext = exports.CommandContext || (exports.CommandContext = {}));
/**
* The command registry composed of commands that are keyboard only
*/
exports.commandRegistry = [];
/**
* A command is just an event emitter with some useful properties relevant to the front end command registry
* such commands cannot have a payload
*/
var UICommand = /** @class */ (function (_super) {
__extends(UICommand, _super);
function UICommand(config) {
var _this = _super.call(this) || this;
_this.config = config;
exports.commandRegistry.push(_this);
return _this;
}
return UICommand;
}(events.TypedEvent));
exports.UICommand = UICommand;
/**
* BAS
*/
// export const bas = new UICommand({
// description: "BAS: I map this to whatever command I am currently testing",
// context: CommandContext.Global,
// });
/**
* General purpose UI escape
*/
exports.esc = new UICommand({
keyboardShortcut: 'esc',
description: "Close any open dialogs and focus back to any open tab",
context: CommandContext.Global,
});
/**
* Active list
*/
exports.gotoNext = new UICommand({
keyboardShortcut: 'mod+f8',
description: "Main Panel : Goto next error in project",
context: CommandContext.Global,
});
exports.gotoPrevious = new UICommand({
keyboardShortcut: 'mod+shift+f8',
description: "Main Panel : Goto previous error in project",
context: CommandContext.Global,
});
/**
* Tabs
*/
exports.nextTab = new UICommand({
keyboardShortcut: 'alt+k',
description: "Tabs: Focus on the Next Tab",
context: CommandContext.Global,
});
exports.prevTab = new UICommand({
keyboardShortcut: 'alt+j',
description: "Tabs: Focus on the Previous Tab",
context: CommandContext.Global,
});
exports.closeTab = new UICommand({
keyboardShortcut: 'alt+w',
description: "Tabs: Close current tab",
context: CommandContext.Global,
});
exports.undoCloseTab = new UICommand({
keyboardShortcut: 'shift+alt+w',
description: "Tabs: Undo close tab",
context: CommandContext.Global,
});
exports.saveTab = new UICommand({
keyboardShortcut: 'mod+s',
description: "Tabs: Save current tab",
context: CommandContext.Global,
});
exports.closeOtherTabs = new UICommand({
description: "Tabs: Close other tabs",
context: CommandContext.Global,
});
exports.closeAllTabs = new UICommand({
description: "Tabs: Close all tabs",
context: CommandContext.Global,
});
exports.jumpToTab = new UICommand({
keyboardShortcut: 'mod+shift+enter',
description: "Tabs: Jump to tab",
context: CommandContext.Global,
});
exports.duplicateTab = new UICommand({
description: "Tabs: Duplicate",
context: CommandContext.Global,
});
exports.duplicateWindow = new UICommand({
description: "Window: Duplicate in a new browser window",
context: CommandContext.Global,
});
/**
* Build / output js
*/
exports.sync = new UICommand({
keyboardShortcut: 'shift+f6',
description: "TypeScript: Sync",
context: CommandContext.Global,
});
exports.build = new UICommand({
keyboardShortcut: 'f6',
description: "TypeScript: Build",
context: CommandContext.Global,
});
exports.toggleOutputJS = new UICommand({
keyboardShortcut: 'mod+shift+m',
description: "TypeScript: Toggle output js file",
context: CommandContext.Global,
});
exports.enableLiveDemo = new UICommand({
description: "TypeScript: Demo file",
context: CommandContext.Global,
});
exports.disableLiveDemo = new UICommand({
description: "TypeScript: Demo stop",
context: CommandContext.Global,
});
exports.enableLiveDemoReact = new UICommand({
description: "TypeScript: Demo react file",
context: CommandContext.Global,
});
exports.disableLiveDemoReact = new UICommand({
description: "TypeScript: Demo react stop",
context: CommandContext.Global,
});
/**
* Tab indexing
* // c9, chrome, atom
*/
exports.gotoTab1 = new UICommand({
keyboardShortcut: 'mod+1',
description: "Tabs: Goto Tab 1",
context: CommandContext.Global,
});
exports.gotoTab2 = new UICommand({
keyboardShortcut: 'mod+2',
description: "Tabs: Goto Tab 2",
context: CommandContext.Global,
});
exports.gotoTab3 = new UICommand({
keyboardShortcut: 'mod+3',
description: "Tabs: Goto Tab 3",
context: CommandContext.Global,
});
exports.gotoTab4 = new UICommand({
keyboardShortcut: 'mod+4',
description: "Tabs: Goto Tab 4",
context: CommandContext.Global,
});
exports.gotoTab5 = new UICommand({
keyboardShortcut: 'mod+5',
description: "Tabs: Goto Tab 5",
context: CommandContext.Global,
});
exports.gotoTab6 = new UICommand({
keyboardShortcut: 'mod+6',
description: "Tabs: Goto Tab 6",
context: CommandContext.Global,
});
exports.gotoTab7 = new UICommand({
keyboardShortcut: 'mod+7',
description: "Tabs: Goto Tab 7",
context: CommandContext.Global,
});
exports.gotoTab8 = new UICommand({
keyboardShortcut: 'mod+8',
description: "Tabs: Goto Tab 8",
context: CommandContext.Global,
});
exports.gotoTab9 = new UICommand({
keyboardShortcut: 'mod+9',
description: "Tabs: Goto Tab 9",
context: CommandContext.Global,
});
/**
* OmniSearch
*/
exports.omniFindFile = new UICommand({
keyboardShortcut: 'mod+o',
description: "Find a file in the working directory",
context: CommandContext.Global,
});
exports.omniFindCommand = new UICommand({
keyboardShortcut: 'mod+shift+p',
description: "Find a command",
context: CommandContext.Global,
});
exports.omniSelectProject = new UICommand({
keyboardShortcut: 'alt+shift+p',
description: "Find and set active project",
context: CommandContext.Global,
});
exports.omniProjectSymbols = new UICommand({
keyboardShortcut: 'mod+shift+h',
description: "Find Symbols (Hieroglyphs) in active project",
context: CommandContext.Global,
});
exports.omniProjectSourcefile = new UICommand({
keyboardShortcut: 'mod+p',
description: "Find Source File in active project",
context: CommandContext.Global,
});
/**
* FAR find and replace
*/
exports.findAndReplace = new UICommand({
keyboardShortcut: 'mod+f',
description: "Show find and replace dialog",
context: CommandContext.Global,
});
exports.findAndReplaceMulti = new UICommand({
keyboardShortcut: 'mod+shift+f',
description: "Show find and replace in files",
context: CommandContext.Global,
});
exports.findNext = new UICommand({
keyboardShortcut: 'f3',
description: "Find the next search result",
context: CommandContext.Global,
});
exports.findPrevious = new UICommand({
keyboardShortcut: 'shift+f3',
description: "Find the previous search result",
context: CommandContext.Global,
});
exports.replaceNext = new events.TypedEvent();
exports.replacePrevious = new events.TypedEvent();
exports.replaceAll = new events.TypedEvent();
/**
* Error panel
*/
exports.toggleMessagePanel = new UICommand({
keyboardShortcut: 'mod+;',
description: "Toggle Message Panel",
context: CommandContext.Global,
});
exports.cycleMessagesPanel = new UICommand({
keyboardShortcut: 'mod+shift+;',
description: "Cycle Message Panel",
context: CommandContext.Global,
});
/**
* Documentation features
*/
exports.toggleDoctor = new UICommand({
keyboardShortcut: "mod+'",
description: "Editor: Toggle Doctor",
context: CommandContext.Global,
});
exports.toggleDocumentationBrowser = new UICommand({
keyboardShortcut: 'mod+shift+\'',
description: "Documentation Browser: Open",
context: CommandContext.Global,
});
exports.doOpenUmlDiagram = new UICommand({
description: "UML Class diagram",
context: CommandContext.Global,
});
exports.toggleSemanticView = new UICommand({
description: "Toggle Semantic View",
context: CommandContext.Global,
});
exports.launchTsFlow = new UICommand({
description: "Launch TypeScript flow based programming",
context: CommandContext.Global,
});
exports.doOpenTestResultsView = new UICommand({
description: "Test Results View",
context: CommandContext.Global,
});
/**
* Cursor history
*/
exports.previousCursorLocation = new UICommand({
keyboardShortcut: "mod+u",
description: "Cursor: Previous Cursor Location",
context: CommandContext.Global,
});
exports.nextCursorLocation = new UICommand({
keyboardShortcut: "mod+shift+u",
description: "Cursor: Next Cursor Location",
context: CommandContext.Global,
});
/**
* Clipboard Ring
*/
exports.copy = new UICommand({
keyboardShortcut: 'mod+c',
description: "Copy",
context: CommandContext.Global,
allowDefault: true
});
exports.cut = new UICommand({
keyboardShortcut: 'mod+x',
description: "Cut",
context: CommandContext.Global,
allowDefault: true
});
exports.pasteFromRing = new UICommand({
keyboardShortcut: 'mod+shift+v',
description: "PasteFromRing",
context: CommandContext.Global,
allowDefault: false
});
/**
* Tree view
*/
exports.treeViewToggle = new UICommand({
keyboardShortcut: 'mod+\\',
description: "Tree View: Toggle",
context: CommandContext.Global,
});
exports.treeViewRevealActiveFile = new UICommand({
keyboardShortcut: 'mod+shift+\\',
description: "Tree View: Reveal Active File",
context: CommandContext.Global,
});
exports.treeViewFocus = new UICommand({
keyboardShortcut: 'mod+0',
description: "Tree View: Focus",
context: CommandContext.Global,
});
exports.treeAddFile = new UICommand({
keyboardShortcut: 'a',
description: "Tree View: Add File",
context: CommandContext.TreeView,
});
exports.treeAddFolder = new UICommand({
keyboardShortcut: 'shift+a',
description: "Tree View: Add Folder",
context: CommandContext.TreeView,
});
exports.treeDuplicateFile = new UICommand({
keyboardShortcut: 'd',
description: "Tree View: Duplicate File|Folder",
context: CommandContext.TreeView,
});
exports.treeMoveFile = new UICommand({
keyboardShortcut: 'm',
description: "Tree View: Move File|Folder",
context: CommandContext.TreeView,
});
/** Rename is same as `move` but people want to search for it */
exports.treeRenameFile = new UICommand({
keyboardShortcut: 'r',
description: "Tree View: Rename File|Folder",
context: CommandContext.TreeView,
});
exports.treeDeleteFile = new UICommand({
keyboardShortcut: 'del',
description: "Tree View: Delete File|Folder",
context: CommandContext.TreeView,
});
exports.treeOpenInExplorerFinder = new UICommand({
keyboardShortcut: 'o',
description: "Tree View: Open folder in explorer / finder",
context: CommandContext.TreeView,
});
exports.treeOpenInCmdTerminal = new UICommand({
keyboardShortcut: 'shift+o',
description: "Tree View: Open folder in cmd / terminal",
context: CommandContext.TreeView,
});
/**
* General purpose file opening
* These are handled in appTabsContainer at the moment
*/
exports.doOpenFile = new events.TypedEvent();
exports.doOpenOrFocusFile = new events.TypedEvent();
exports.openFileFromDisk = new UICommand({
keyboardShortcut: 'mod+shift+o',
description: 'Open a file present on server disk',
context: CommandContext.Global,
});
/** needed by cursor history */
exports.doOpenOrFocusTab = new events.TypedEvent();
/** needed by file tree */
exports.closeFilesDirs = new events.TypedEvent();
/** Needed by file tree, activates the tab but doesn't change focus away from tree view */
exports.doOpenOrActivateFileTab = new events.TypedEvent();
/** Needed to toggle output js file. We toggle and also do not steal focus */
exports.doToggleFileTab = new events.TypedEvent();
/** Needed to ensure that a demo view is open */
exports.ensureLiveDemoTab = new events.TypedEvent();
exports.closeDemoTab = new events.TypedEvent();
exports.ensureLiveDemoReactTab = new events.TypedEvent();
exports.closeDemoReactTab = new events.TypedEvent();
/**
* Other tab types
*/
exports.doOpenDependencyView = new UICommand({
description: 'Open Dependency View',
context: CommandContext.Global,
});
exports.doOpenASTView = new UICommand({
description: 'Open AST View',
context: CommandContext.Global,
});
exports.doOpenASTFullView = new UICommand({
description: 'Open AST-Full View',
context: CommandContext.Global,
});
/**
* Common configuration file creations
*/
exports.createEditorconfig = new UICommand({
description: 'Create a .editorconfig',
context: CommandContext.Global,
});
/**
* Settings stuff
*/
exports.openSettingsFile = new UICommand({
description: 'Open settings file',
context: CommandContext.Global
});
/**
* Git
*/
exports.gitAddAllCommitAndPush = new UICommand({
description: 'Git: Add all, Commit and Push',
context: CommandContext.Global
});
exports.gitFetchLatestAndRebase = new UICommand({
description: 'Git: Fetch + Pull latest, and rebase any local commits',
context: CommandContext.Global
});
/** Whenever status might be invalid */
exports.gitStatusNeedsRefresh = new events.TypedEvent();
/**
* Registration
*/
function register() {
exports.commandRegistry.forEach(function (c) {
if (c.config.context == CommandContext.Global
&& c.config.keyboardShortcut) {
Mousetrap.bindGlobal(c.config.keyboardShortcut, function () {
c.emit({});
return !!c.config.allowDefault;
});
}
});
}
exports.register = register;
/**
*
* CODE MIRROR
*
*/
/**
* Straight out of codemirror.js
*/
exports.ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
exports.mac = exports.ios || /Mac/.test(navigator.platform);
exports.windows = /win/i.test(navigator.platform);
/** Nice display name for the mod by user platform */
exports.modName = exports.mac ? '⌘' : 'Ctrl';
var mod = exports.mac ? 'Cmd' : 'Ctrl';
/** Load editor actions + keymaps */
var monacoActionLoader_1 = require("./monacoActionLoader");
var actions = monacoActionLoader_1.getActions();
// console.log(actions); // DEBUG
if (exports.mac) {
// TODO: mon
// Prevent the browser from handling the CMD + SHIFT + [ (or ]) which monaco uses for fold / unfold
}
function addEditorMapToCommands(command) {
new UICommand({
keyboardShortcut: command.kbd,
description: "Editor: " + command.label,
context: CommandContext.Editor,
editorCommandName: command.id,
});
}
actions.forEach(addEditorMapToCommands);
/**
* This is a consolidation of the `file edited` and `file changed on disk`
*/
exports.fileContentsChanged = new events.TypedEvent();
/**
* Setup toasts to hide on esc
* Note: this is done here instead of `ui` as some commands depend on `ui` and having depend on commands causes a circular dependency
*/
var toastr = require("toastr");
exports.esc.on(function () {
toastr.clear();
});
/* DEBUG
console.table(
commandRegistry
.filter(c=>c.config.context == CommandContext.Editor)
.map(c=>({cmd:c.config.description, shortcut:c.config.keyboardShortcut}))
);
/* DEBUG */
/**
* Mac (the chrome browser in mac) doesn't have *cmd + y* (common redo).
* Instead it opens the browser history by mistake.
* So we redirect it to redo for any open editor :)
*/
Mousetrap.bindGlobal('mod+y', function (event) {
// If the focus is on editor than monaco already handles it
// If we made it till here .... then ....
// Prevent default
return false;
});
/**
* Mac: Cmd + H at the wrong place hides the window.
*/
Mousetrap.bindGlobal('mod+h', function (event) {
// If the focus is on editor than monaco already handles it
// If we made it till here .... then ....
// Prevent default
return false;
});