mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
parent
90aa979bb7
commit
802a170eff
|
@ -66,7 +66,7 @@ import { Color } from 'vs/base/common/color';
|
|||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { TerminalStorageKeys } from 'vs/workbench/contrib/terminal/common/terminalStorageKeys';
|
||||
import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey';
|
||||
import { getTerminalUri } from 'vs/workbench/contrib/terminal/browser/terminalUri';
|
||||
import { getTerminalResourcesFromDragEvent, getTerminalUri } from 'vs/workbench/contrib/terminal/browser/terminalUri';
|
||||
|
||||
// How long in milliseconds should an average frame take to render for a notification to appear
|
||||
// which suggests the fallback DOM-based renderer
|
||||
|
@ -2071,14 +2071,9 @@ class TerminalInstanceDragAndDropController extends Disposable implements IDragA
|
|||
return;
|
||||
}
|
||||
|
||||
const terminalResources = e.dataTransfer.getData(DataTransfers.TERMINALS);
|
||||
const terminalResources = getTerminalResourcesFromDragEvent(e);
|
||||
if (terminalResources) {
|
||||
const json = JSON.parse(terminalResources);
|
||||
for (const entry of json) {
|
||||
const uri = URI.from({
|
||||
scheme: Schemas.vscodeTerminal,
|
||||
path: URI.parse(entry).path
|
||||
});
|
||||
for (const uri of terminalResources) {
|
||||
const side = this._getDropSide(e);
|
||||
this._onDropTerminal.fire({ uri, side });
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecy
|
|||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { IProcessDetails } from 'vs/platform/terminal/common/terminalProcess';
|
||||
import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey';
|
||||
import { parseTerminalUri } from 'vs/workbench/contrib/terminal/browser/terminalUri';
|
||||
import { getTerminalResourcesFromDragEvent, parseTerminalUri } from 'vs/workbench/contrib/terminal/browser/terminalUri';
|
||||
|
||||
const $ = DOM.$;
|
||||
|
||||
|
@ -620,12 +620,9 @@ class TerminalTabsDragAndDrop implements IListDragAndDrop<ITerminalInstance> {
|
|||
|
||||
let sourceInstances: ITerminalInstance[] | undefined;
|
||||
let promises: Promise<IProcessDetails | undefined>[] = [];
|
||||
const resources = originalEvent.dataTransfer?.getData(DataTransfers.TERMINALS);
|
||||
const resources = getTerminalResourcesFromDragEvent(originalEvent);
|
||||
if (resources) {
|
||||
const json = JSON.parse(resources);
|
||||
for (const entry of json) {
|
||||
const uri = URI.parse(entry);
|
||||
|
||||
for (const uri of resources) {
|
||||
const instance = this._terminalService.getInstanceFromResource(uri);
|
||||
if (instance) {
|
||||
sourceInstances = [instance];
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { DataTransfers } from 'vs/base/browser/dnd';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
|
@ -26,3 +27,20 @@ export interface ITerminalIdentifier {
|
|||
workspaceId: string;
|
||||
instanceId: number | undefined;
|
||||
}
|
||||
|
||||
export interface IPartialDragEvent {
|
||||
dataTransfer: Pick<DataTransfer, 'getData'> | null;
|
||||
}
|
||||
|
||||
export function getTerminalResourcesFromDragEvent(event: IPartialDragEvent): URI[] | undefined {
|
||||
const resources = event.dataTransfer?.getData(DataTransfers.TERMINALS);
|
||||
if (resources) {
|
||||
const json = JSON.parse(resources);
|
||||
const result = [];
|
||||
for (const entry of json) {
|
||||
result.push(URI.parse(entry));
|
||||
}
|
||||
return result.length === 0 ? undefined : result;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { deepStrictEqual } from 'assert';
|
||||
import { getTerminalResourcesFromDragEvent, IPartialDragEvent } from 'vs/workbench/contrib/terminal/browser/terminalUri';
|
||||
|
||||
function fakeDragEvent(data: string): IPartialDragEvent {
|
||||
return {
|
||||
dataTransfer: {
|
||||
getData: () => {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
suite('getTerminalResourcesFromDragEvent', () => {
|
||||
test('should give undefined when no terminal resources is in event', () => {
|
||||
deepStrictEqual(
|
||||
getTerminalResourcesFromDragEvent(fakeDragEvent(''))?.map(e => e.toString()),
|
||||
undefined
|
||||
);
|
||||
});
|
||||
test('should give undefined when an empty terminal resources array is in event', () => {
|
||||
deepStrictEqual(
|
||||
getTerminalResourcesFromDragEvent(fakeDragEvent('[]'))?.map(e => e.toString()),
|
||||
undefined
|
||||
);
|
||||
});
|
||||
test('should return terminal resource when event contains one', () => {
|
||||
deepStrictEqual(
|
||||
getTerminalResourcesFromDragEvent(fakeDragEvent('["vscode-terminal:/1626874386474/3"]'))?.map(e => e.toString()),
|
||||
['vscode-terminal:/1626874386474/3']
|
||||
);
|
||||
});
|
||||
test('should return multiple terminal resources when event contains multiple', () => {
|
||||
deepStrictEqual(
|
||||
getTerminalResourcesFromDragEvent(fakeDragEvent('["vscode-terminal:/foo/1","vscode-terminal:/bar/2"]'))?.map(e => e.toString()),
|
||||
['vscode-terminal:/foo/1', 'vscode-terminal:/bar/2']
|
||||
);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue