UNPKG

sprotty-vscode-webview

Version:

Integration of Sprotty in a VS Code extensions (WebView part)

65 lines 2.46 kB
"use strict"; /******************************************************************************** * Copyright (c) 2020 TypeFox and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the Eclipse * Public License v. 2.0 are satisfied: GNU General Public License, version 2 * with the GNU Classpath Exception which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ Object.defineProperty(exports, "__esModule", { value: true }); exports.TraceableMouseListener = exports.getURI = exports.getRange = exports.isTraceable = void 0; const sprotty_1 = require("sprotty"); const sprotty_protocol_1 = require("sprotty-protocol"); const vscode_uri_1 = require("vscode-uri"); function isTraceable(element) { return !!element.trace && !!getRange(element.trace); } exports.isTraceable = isTraceable; function getRange(thing) { const trace = typeof thing === 'string' ? thing : thing.trace; if (!trace) return undefined; const query = vscode_uri_1.URI.parse(trace).query; const numbers = query.split(/[:-]/).map(s => parseInt(s, 10)); if (numbers.length !== 4 || numbers.find(isNaN) !== undefined) return undefined; return { start: { line: numbers[0], character: numbers[1] }, end: { line: numbers[2], character: numbers[3] } }; } exports.getRange = getRange; function getURI(traceable) { return vscode_uri_1.URI.parse(traceable.trace).with({ query: null, fragment: null }); } exports.getURI = getURI; class TraceableMouseListener extends sprotty_1.MouseListener { doubleClick(target, event) { const traceable = (0, sprotty_1.findParent)(target, (element) => isTraceable(element)); if (traceable) return [sprotty_protocol_1.OpenAction.create(traceable.id)]; else return []; } } exports.TraceableMouseListener = TraceableMouseListener; //# sourceMappingURL=traceable.js.map