feat: 添加vscode编辑器

This commit is contained in:
dhx
2022-09-29 16:48:09 +08:00
parent a93bdac4ff
commit 150898ec1e
1126 changed files with 933348 additions and 0 deletions
@@ -0,0 +1,107 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { DataTransfers } from '../../../base/browser/dnd.js';
import { parse } from '../../../base/common/marshalling.js';
import { URI } from '../../../base/common/uri.js';
import { extractSelection } from '../../opener/common/opener.js';
import { Registry } from '../../registry/common/platform.js';
//#region Editor / Resources DND
export const CodeDataTransfers = {
EDITORS: 'CodeEditors',
FILES: 'CodeFiles'
};
export function extractEditorsDropData(e) {
var _a;
const editors = [];
if (e.dataTransfer && e.dataTransfer.types.length > 0) {
// Data Transfer: Code Editors
const rawEditorsData = e.dataTransfer.getData(CodeDataTransfers.EDITORS);
if (rawEditorsData) {
try {
editors.push(...parse(rawEditorsData));
}
catch (error) {
// Invalid transfer
}
}
// Data Transfer: Resources
else {
try {
const rawResourcesData = e.dataTransfer.getData(DataTransfers.RESOURCES);
editors.push(...createDraggedEditorInputFromRawResourcesData(rawResourcesData));
}
catch (error) {
// Invalid transfer
}
}
// Check for native file transfer
if ((_a = e.dataTransfer) === null || _a === void 0 ? void 0 : _a.files) {
for (let i = 0; i < e.dataTransfer.files.length; i++) {
const file = e.dataTransfer.files[i];
if (file && file.path /* Electron only */) {
try {
editors.push({ resource: URI.file(file.path), isExternal: true, allowWorkspaceOpen: true });
}
catch (error) {
// Invalid URI
}
}
}
}
// Check for CodeFiles transfer
const rawCodeFiles = e.dataTransfer.getData(CodeDataTransfers.FILES);
if (rawCodeFiles) {
try {
const codeFiles = JSON.parse(rawCodeFiles);
for (const codeFile of codeFiles) {
editors.push({ resource: URI.file(codeFile), isExternal: true, allowWorkspaceOpen: true });
}
}
catch (error) {
// Invalid transfer
}
}
// Workbench contributions
const contributions = Registry.as(Extensions.DragAndDropContribution).getAll();
for (const contribution of contributions) {
const data = e.dataTransfer.getData(contribution.dataFormatKey);
if (data) {
try {
editors.push(...contribution.getEditorInputs(data));
}
catch (error) {
// Invalid transfer
}
}
}
}
return editors;
}
export function createDraggedEditorInputFromRawResourcesData(rawResourcesData) {
const editors = [];
if (rawResourcesData) {
const resourcesRaw = JSON.parse(rawResourcesData);
for (const resourceRaw of resourcesRaw) {
if (resourceRaw.indexOf(':') > 0) { // mitigate https://github.com/microsoft/vscode/issues/124946
const { selection, uri } = extractSelection(URI.parse(resourceRaw));
editors.push({ resource: uri, options: { selection } });
}
}
}
return editors;
}
class DragAndDropContributionRegistry {
constructor() {
this._contributions = new Map();
}
getAll() {
return this._contributions.values();
}
}
export const Extensions = {
DragAndDropContribution: 'workbench.contributions.dragAndDrop'
};
Registry.add(Extensions.DragAndDropContribution, new DragAndDropContributionRegistry());
//#endregion