UNPKG

alm

Version:

The best IDE for TypeScript

108 lines (107 loc) 3.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var typestyle = require("typestyle"); var commands = require("../../commands/commands"); /** * Some styles */ /** * We have a unified color in overview as * having three colors there is mentally overloading **/ var colorInOverView = 'rgba(0, 122, 204, 0.6)'; var addedColor = '#008A00'; var addedClassName = typestyle.style({ borderLeft: "3px solid " + addedColor, marginLeft: "5px" }); var addedDecorationOptions = { linesDecorationsClassName: addedClassName, isWholeLine: true, overviewRuler: { color: colorInOverView, darkColor: colorInOverView, position: monaco.editor.OverviewRulerLane.Left } }; var modifiedColor = 'yellow'; var modifiedClassName = typestyle.style({ borderLeft: "3px solid " + modifiedColor, marginLeft: "5px" }); var modifiedDecorationOptions = { linesDecorationsClassName: modifiedClassName, isWholeLine: true, overviewRuler: { color: colorInOverView, darkColor: colorInOverView, position: monaco.editor.OverviewRulerLane.Left } }; var removedColor = '#00ccff'; var removedClassName = typestyle.style({ borderLeft: "3px solid " + removedColor, marginLeft: "5px" }); var removedDecorationOptions = { linesDecorationsClassName: removedClassName, isWholeLine: true, overviewRuler: { color: colorInOverView, darkColor: colorInOverView, position: monaco.editor.OverviewRulerLane.Left } }; var events_1 = require("../../../common/events"); var utils = require("../../../common/utils"); var socketClient_1 = require("../../../socket/socketClient"); function setup(editor) { // if (editor) return { dispose: () => null }; // DEBUG : while the feature isn't complete used to disable it var filePath = editor.filePath; var lastDecorations = []; var refreshGitStatus = function () { socketClient_1.server.gitDiff({ filePath: filePath }).then(function (res) { // Add to new var addedDecorations = res.added.map(function (added) { var result = { range: { startLineNumber: added.from + 1, endLineNumber: added.to + 1, }, options: addedDecorationOptions }; return result; }); var modifiedDecorations = res.modified.map(function (modified) { var result = { range: { startLineNumber: modified.from + 1, endLineNumber: modified.to + 1, }, options: modifiedDecorationOptions }; return result; }); var removedDecorations = res.removed.map(function (removed) { var result = { range: { startLineNumber: removed + 1, endLineNumber: removed + 1, }, options: removedDecorationOptions }; return result; }); // Collect all the decorations and apply them var deltaDecorations = addedDecorations.concat(modifiedDecorations).concat(removedDecorations); lastDecorations = editor.deltaDecorations(lastDecorations, deltaDecorations); }); }; var refreshGitStatusDebounced = utils.debounce(refreshGitStatus, 2000); var disposible = new events_1.CompositeDisposible(); disposible.add(editor.onDidFocusEditor(refreshGitStatusDebounced)); disposible.add(editor.onDidChangeModelContent(refreshGitStatusDebounced)); disposible.add(commands.gitStatusNeedsRefresh.on(refreshGitStatusDebounced)); return disposible; } exports.setup = setup;