UNPKG

theia-sprotty

Version:

Glue code for sprotty diagrams in a Theia IDE

97 lines 4.02 kB
"use strict"; /* * Copyright (C) 2018 TypeFox and others. * * Licensed under the Apache License, Version 2.0 (the "License") you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 */ 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 }); var lib_1 = require("sprotty/lib"); var workspace_edit_command_1 = require("./workspace-edit-command"); var ranged_1 = require("./ranged"); var DeleteWithWorkspaceEditCommand = /** @class */ (function (_super) { __extends(DeleteWithWorkspaceEditCommand, _super); function DeleteWithWorkspaceEditCommand(action) { var _this = _super.call(this) || this; _this.action = action; return _this; } Object.defineProperty(DeleteWithWorkspaceEditCommand.prototype, "workspace", { get: function () { return this.action.workspace; }, enumerable: true, configurable: true }); DeleteWithWorkspaceEditCommand.prototype.createWorkspaceEdit = function (context) { var _a; var elementsToBeDeleted = this.findElementsToBeDeleted(context.root); var textEdits = []; // TODO: consider URIs from element traces elementsToBeDeleted.forEach(function (e) { textEdits.push({ range: ranged_1.toLsRange(e.range), newText: '' }); }); var workspaceEdit = { changes: (_a = {}, _a[this.action.sourceUri] = textEdits, _a) }; return workspaceEdit; }; DeleteWithWorkspaceEditCommand.prototype.findElementsToBeDeleted = function (root) { var _this = this; var elements = new Set(); var index = root.index; index.all().forEach(function (e) { if (e && _this.shouldDelete(e)) elements.add(e); else if (e instanceof lib_1.SEdge && ranged_1.isRanged(e)) { var source = index.getById(e.sourceId); var target = index.getById(e.targetId); if (_this.shouldDeleteParent(source) || _this.shouldDeleteParent(target)) elements.add(e); } }); return elements; }; DeleteWithWorkspaceEditCommand.prototype.shouldDelete = function (e) { return lib_1.isSelectable(e) && e.selected && ranged_1.isRanged(e); }; DeleteWithWorkspaceEditCommand.prototype.shouldDeleteParent = function (source) { while (source) { if (this.shouldDelete(source)) { return true; } source = (source instanceof lib_1.SChildElement) ? source.parent : undefined; } return false; }; DeleteWithWorkspaceEditCommand.KIND = 'deleteWithWorkspaceEdit'; return DeleteWithWorkspaceEditCommand; }(workspace_edit_command_1.AbstractWorkspaceEditCommand)); exports.DeleteWithWorkspaceEditCommand = DeleteWithWorkspaceEditCommand; var DeleteWithWorkspaceEditAction = /** @class */ (function () { // TODO: consider URIs from individual element traces function DeleteWithWorkspaceEditAction(workspace, sourceUri) { this.workspace = workspace; this.sourceUri = sourceUri; this.kind = DeleteWithWorkspaceEditCommand.KIND; } return DeleteWithWorkspaceEditAction; }()); exports.DeleteWithWorkspaceEditAction = DeleteWithWorkspaceEditAction; //# sourceMappingURL=delete.js.map