From d2a73c0c445fb95c1ecf6c0f3145343c4b6a4ddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Thu, 13 Apr 2023 10:46:27 +0200 Subject: [PATCH] Fix check for presence of files in DnD. Fixes #12404 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also clears "local transfers" when drag ends, preventing the items from a previous D&D operation to spill over to the next one. Contributed on behalf of STMicroelectronics Signed-off-by: Thomas Mäder --- packages/plugin-ext/src/common/plugin-api-rpc.ts | 1 + .../src/main/browser/view/tree-view-widget.tsx | 12 +++++++++++- packages/plugin-ext/src/plugin/tree/tree-views.ts | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/plugin-ext/src/common/plugin-api-rpc.ts b/packages/plugin-ext/src/common/plugin-api-rpc.ts index e375511feb536..becd5404dd3f7 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc.ts @@ -756,6 +756,7 @@ export class DataTransferFileDTO { export interface TreeViewsExt { $dragStarted(treeViewId: string, treeItemIds: string[], token: CancellationToken): Promise; + $dragEnd(treeViewId: string): Promise; $drop(treeViewId: string, treeItemId: string | undefined, dataTransferItems: [string, string | DataTransferFileDTO][], token: CancellationToken): Promise; $getChildren(treeViewId: string, treeItemId: string | undefined): Promise; $hasResolveTreeItem(treeViewId: string): Promise; diff --git a/packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx b/packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx index 3752f79d1d8e8..8a95a78310e95 100644 --- a/packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx +++ b/packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx @@ -632,13 +632,23 @@ export class TreeViewWidget extends TreeViewWelcomeWidget { handleDragEnd(node: TreeViewNode, event: React.DragEvent): void { this.applicationShell.clearAdditionalDraggedEditorUris(); + this.model.proxy!.$dragEnd(this.id); } handleDragOver(event: React.DragEvent): void { + const hasFiles = (items: DataTransferItemList) => { + for (let i = 0; i < items.length; i++) { + if (items[i].kind === 'file') { + return true; + } + } + return false; + }; + if (event.dataTransfer) { const canDrop = event.dataTransfer.types.some(type => this.options.dropMimeTypes!.includes(type)) || event.dataTransfer.types.includes(this.treeDragType) || - this.options.dropMimeTypes!.includes('files') && event.dataTransfer.files.length > 0; + this.options.dropMimeTypes!.includes('files') && hasFiles(event.dataTransfer.items); if (canDrop) { event.preventDefault(); event.dataTransfer.dropEffect = 'move'; diff --git a/packages/plugin-ext/src/plugin/tree/tree-views.ts b/packages/plugin-ext/src/plugin/tree/tree-views.ts index 11715b0cee801..06fa967b0fe59 100644 --- a/packages/plugin-ext/src/plugin/tree/tree-views.ts +++ b/packages/plugin-ext/src/plugin/tree/tree-views.ts @@ -58,6 +58,10 @@ export class TreeViewsExtImpl implements TreeViewsExt { return this.getTreeView(treeViewId).onDragStarted(treeItemIds, token); } + $dragEnd(treeViewId: string): Promise { + return this.getTreeView(treeViewId).dragEnd(); + } + $drop(treeViewId: string, treeItemId: string | undefined, dataTransferItems: [string, string | DataTransferFileDTO][], token: CancellationToken): Promise { return this.getTreeView(treeViewId).handleDrop!(treeItemId, dataTransferItems, token); } @@ -606,6 +610,10 @@ class TreeViewExtImpl implements Disposable { return undefined; } + async dragEnd(): Promise { + this.localDataTransfer.clear(); + } + async handleDrop(treeItemId: string | undefined, dataTransferItems: [string, string | DataTransferFileDTO][], token: CancellationToken): Promise { const treeItem = treeItemId ? this.getElement(treeItemId) : undefined; const dropTransfer = new DataTransfer();