Skip to content

Commit

Permalink
Support terminal editor -> panel dnd
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar authored and suzmue committed Jun 21, 2021
1 parent bb093e1 commit b40e29c
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions src/vs/workbench/contrib/terminal/browser/terminalTabsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,14 @@ class TerminalTabsDragAndDrop implements IListDragAndDrop<ITerminalInstance> {
}

onDragOver(data: IDragAndDropData, targetInstance: ITerminalInstance | undefined, targetIndex: number | undefined, originalEvent: DragEvent): boolean | IListDragOverReaction {
if (containsDragType(originalEvent, DataTransfers.TERMINALS)) {
return {
feedback: targetIndex ? [targetIndex] : undefined,
accept: true,
effect: ListDragOverEffect.Move
};
}

if (data instanceof NativeDragAndDropData) {
if (!containsDragType(originalEvent, DataTransfers.FILES, DataTransfers.RESOURCES)) {
return false;
Expand Down Expand Up @@ -594,21 +602,35 @@ class TerminalTabsDragAndDrop implements IListDragAndDrop<ITerminalInstance> {
this._autoFocusDisposable.dispose();
this._autoFocusInstance = undefined;

if (!(data instanceof ElementsDragAndDropData)) {
this._handleExternalDrop(targetInstance, originalEvent);
return;
let sourceInstances: ITerminalInstance[] | undefined;
const terminalResources = originalEvent.dataTransfer?.getData(DataTransfers.TERMINALS);
if (terminalResources) {
const uri = URI.parse(JSON.parse(terminalResources)[0]);
if (uri.scheme === Schemas.vscodeTerminal) {
const instance = this._terminalService.instances.find(e => e.resource.path === uri.path);
if (instance) {
sourceInstances = [instance];
}
this._terminalService.moveToTerminalView(instance);
}
}

const draggedElement = data.getData();
if (!draggedElement || !Array.isArray(draggedElement)) {
return;
}
let focused = false;
if (sourceInstances === undefined) {
if (!(data instanceof ElementsDragAndDropData)) {
this._handleExternalDrop(targetInstance, originalEvent);
return;
}

let sourceInstances: ITerminalInstance[] = [];
for (const e of draggedElement) {
if ('instanceId' in e) {
sourceInstances.push(e as ITerminalInstance);
const draggedElement = data.getData();
if (!draggedElement || !Array.isArray(draggedElement)) {
return;
}

sourceInstances = [];
for (const e of draggedElement) {
if ('instanceId' in e) {
sourceInstances.push(e as ITerminalInstance);
}
}
}

Expand All @@ -619,6 +641,7 @@ class TerminalTabsDragAndDrop implements IListDragAndDrop<ITerminalInstance> {
return;
}

let focused = false;
for (const instance of sourceInstances) {
this._terminalGroupService.moveGroup(instance, targetInstance);
if (!focused) {
Expand Down

0 comments on commit b40e29c

Please sign in to comment.