Skip to content

Commit d122abd

Browse files
committed
Allow tree drop at root
Fixes microsoft#145904
1 parent 6829684 commit d122abd

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

src/vs/workbench/api/browser/mainThreadTreeViews.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ class TreeViewDragAndDropController implements ITreeViewDragAndDropController {
175175
readonly hasWillDrop: boolean,
176176
private readonly _proxy: ExtHostTreeViewsShape) { }
177177

178-
async handleDrop(dataTransfer: IDataTransfer, targetTreeItem: ITreeItem, token: CancellationToken,
178+
async handleDrop(dataTransfer: IDataTransfer, targetTreeItem: ITreeItem | undefined, token: CancellationToken,
179179
operationUuid?: string, sourceTreeId?: string, sourceTreeItemHandles?: string[]): Promise<void> {
180-
return this._proxy.$handleDrop(this.treeViewId, await DataTransferConverter.toDataTransferDTO(dataTransfer), targetTreeItem.handle, token, operationUuid, sourceTreeId, sourceTreeItemHandles);
180+
return this._proxy.$handleDrop(this.treeViewId, await DataTransferConverter.toDataTransferDTO(dataTransfer), targetTreeItem?.handle, token, operationUuid, sourceTreeId, sourceTreeItemHandles);
181181
}
182182

183183
async handleDrag(sourceTreeItemHandles: string[], operationUuid: string, token: CancellationToken): Promise<IDataTransfer | undefined> {

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ export interface ExtHostDocumentsAndEditorsShape {
13301330

13311331
export interface ExtHostTreeViewsShape {
13321332
$getChildren(treeViewId: string, treeItemHandle?: string): Promise<ITreeItem[] | undefined>;
1333-
$handleDrop(destinationViewId: string, treeDataTransfer: DataTransferDTO, newParentTreeItemHandle: string, token: CancellationToken, operationUuid?: string, sourceViewId?: string, sourceTreeItemHandles?: string[]): Promise<void>;
1333+
$handleDrop(destinationViewId: string, treeDataTransfer: DataTransferDTO, targetHandle: string | undefined, token: CancellationToken, operationUuid?: string, sourceViewId?: string, sourceTreeItemHandles?: string[]): Promise<void>;
13341334
$handleDrag(sourceViewId: string, sourceTreeItemHandles: string[], operationUuid: string, token: CancellationToken): Promise<DataTransferDTO | undefined>;
13351335
$setExpanded(treeViewId: string, treeItemHandle: string, expanded: boolean): void;
13361336
$setSelection(treeViewId: string, treeItemHandles: string[]): void;

src/vs/workbench/api/common/extHostTreeViews.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class ExtHostTreeViews implements ExtHostTreeViewsShape {
135135
return treeView.getChildren(treeItemHandle);
136136
}
137137

138-
async $handleDrop(destinationViewId: string, treeDataTransferDTO: DataTransferDTO, newParentItemHandle: string, token: CancellationToken,
138+
async $handleDrop(destinationViewId: string, treeDataTransferDTO: DataTransferDTO, targetItemHandle: string | undefined, token: CancellationToken,
139139
operationUuid?: string, sourceViewId?: string, sourceTreeItemHandles?: string[]): Promise<void> {
140140
const treeView = this.treeViews.get(destinationViewId);
141141
if (!treeView) {
@@ -146,7 +146,7 @@ export class ExtHostTreeViews implements ExtHostTreeViewsShape {
146146
if ((sourceViewId === destinationViewId) && sourceTreeItemHandles) {
147147
await this.addAdditionalTransferItems(treeDataTransfer, treeView, sourceTreeItemHandles, token, operationUuid);
148148
}
149-
return treeView.onDrop(treeDataTransfer, newParentItemHandle, token);
149+
return treeView.onDrop(treeDataTransfer, targetItemHandle, token);
150150
}
151151

152152
private async addAdditionalTransferItems(treeDataTransfer: IDataTransfer, treeView: ExtHostTreeView<any>,
@@ -452,9 +452,9 @@ class ExtHostTreeView<T> extends Disposable {
452452
return !!this.dndController?.handleDrag;
453453
}
454454

455-
async onDrop(treeDataTransfer: vscode.DataTransfer, targetHandleOrNode: TreeItemHandle, token: CancellationToken): Promise<void> {
456-
const target = this.getExtensionElement(targetHandleOrNode);
457-
if (!target || !this.dndController?.handleDrop) {
455+
async onDrop(treeDataTransfer: vscode.DataTransfer, targetHandleOrNode: TreeItemHandle | undefined, token: CancellationToken): Promise<void> {
456+
const target = targetHandleOrNode ? this.getExtensionElement(targetHandleOrNode) : undefined;
457+
if ((!target && targetHandleOrNode) || !this.dndController?.handleDrop) {
458458
return;
459459
}
460460
return asPromise(() => this.dndController?.handleDrop

src/vs/workbench/browser/parts/views/treeView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ export class CustomTreeViewDragAndDrop implements ITreeDragAndDrop<ITreeItem> {
14191419

14201420
async drop(data: IDragAndDropData, targetNode: ITreeItem | undefined, targetIndex: number | undefined, originalEvent: DragEvent): Promise<void> {
14211421
const dndController = this.dndController;
1422-
if (!originalEvent.dataTransfer || !dndController || !targetNode) {
1422+
if (!originalEvent.dataTransfer || !dndController) {
14231423
return;
14241424
}
14251425
const treeDataTransfer: IDataTransfer = new Map();
@@ -1443,7 +1443,7 @@ export class CustomTreeViewDragAndDrop implements ITreeDragAndDrop<ITreeItem> {
14431443
}
14441444
}
14451445

1446-
if (!originalEvent.dataTransfer || !targetNode) {
1446+
if (!originalEvent.dataTransfer) {
14471447
return;
14481448
}
14491449
for (const dataItem of originalEvent.dataTransfer.items) {

src/vs/workbench/common/views.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ export interface ITreeViewDragAndDropController {
830830
readonly dropMimeTypes: string[];
831831
readonly dragMimeTypes: string[];
832832
handleDrag(sourceTreeItemHandles: string[], operationUuid: string, token: CancellationToken): Promise<IDataTransfer | undefined>;
833-
handleDrop(elements: IDataTransfer, target: ITreeItem, token: CancellationToken, operationUuid?: string, sourceTreeId?: string, sourceTreeItemHandles?: string[]): Promise<void>;
833+
handleDrop(elements: IDataTransfer, target: ITreeItem | undefined, token: CancellationToken, operationUuid?: string, sourceTreeId?: string, sourceTreeItemHandles?: string[]): Promise<void>;
834834
}
835835

836836
export interface IEditableData {

src/vscode-dts/vscode.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9860,10 +9860,10 @@ declare module 'vscode' {
98609860
* Extensions should fire {@link TreeDataProvider.onDidChangeTreeData onDidChangeTreeData} for any elements that need to be refreshed.
98619861
*
98629862
* @param dataTransfer The data transfer items of the source of the drag.
9863-
* @param target The target tree element that the drop is occurring on.
9863+
* @param target The target tree element that the drop is occurring on. When undefined, the target is the root.
98649864
* @param token A cancellation token indicating that the drop has been cancelled.
98659865
*/
9866-
handleDrop?(target: T, dataTransfer: DataTransfer, token: CancellationToken): Thenable<void> | void;
9866+
handleDrop?(target: T | undefined, dataTransfer: DataTransfer, token: CancellationToken): Thenable<void> | void;
98679867
}
98689868

98699869
/**

0 commit comments

Comments
 (0)