Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot insert custom data on drag-and-drop of vscode.TreeItem to editor #210023

Closed
ajaygera opened this issue Apr 10, 2024 · 7 comments
Closed

cannot insert custom data on drag-and-drop of vscode.TreeItem to editor #210023

ajaygera opened this issue Apr 10, 2024 · 7 comments
Assignees
Labels
feature-request Request for new features or functionality tree-views Extension tree view issues

Comments

@ajaygera
Copy link

ajaygera commented Apr 10, 2024

Does this issue occur when all extensions are disabled?: Yes/No

  • VS Code Version: 1.88
  • OS Version: Windows 11

Steps to Reproduce:

  1. I need to drag a vscode.TreeItem (node) on the editor and need to insert some data based upon node which is dragged.
    To achieve this, I have followed sample - https://github.com/microsoft/vscode-extension-samples/blob/main/tree-view-sample/src/testViewDragAndDrop.ts
    This sample inserts content of resourceUri property on vscode.TreeItem prefix with \

  2. On handleDrag() method if we specify file uri to 'text/uri-list' MIME type (as shown in below code snippet) then drag and drop on editor opens new file as specified in file URI and
    If we press shift key and drop then it inserts file uri path i.e. c:\office.txt rather than inserting content of file.

public async handleDrag(source: Node[], treeDataTransfer: vscode.DataTransfer, token: vscode.CancellationToken): Promise<void> {
		treeDataTransfer.set('application/vnd.code.tree.testViewDragAndDrop', new vscode.DataTransferItem(source));		
		let uri = vscode.Uri.parse("file:///C:/office/1.txt");		
		let dataTransferItem = new vscode.DataTransferItem(uri.toString());        
		 treeDataTransfer.set('text/uri-list', dataTransferItem);
	}
  1. To insert custom data i have implemented one more interface vscode.DocumentDropEditProvider (code snippet shows). Can this be used to insert data for drag and drop of vscode.treeview node to editor? Documentation says it is used to drag and drop files
class FileNameListOnDropProvider implements vscode.DocumentDropEditProvider {
	async provideDocumentDropEdits(
		_document: vscode.TextDocument,
		_position: vscode.Position,
		dataTransfer: vscode.DataTransfer,
		token: vscode.CancellationToken
	): Promise<vscode.DocumentDropEdit | undefined> {
		// Check the data transfer to see if we have dropped a list of uris
		const dataTransferItem = dataTransfer.get(uriListMime);
		if (!dataTransferItem) {
			return undefined;
		}

		// 'text/uri-list' contains a list of uris separated by new lines.
		// Parse this to an array of uris.
		const urlList = await dataTransferItem.asString();
		if (token.isCancellationRequested) {
			return undefined;
		}

		const uris: vscode.Uri[] = [];
		for (const resource of urlList.split('\n')) {
			try {
				uris.push(vscode.Uri.parse(resource));
			} catch {
				// noop
			}
		}

		if (!uris.length) {
			return undefined;
		}

		// Build a snippet to insert
		const snippet = new vscode.SnippetString();
		uris.forEach((uri, index) => {
			const name = path.basename(uri.path);
			snippet.appendText(`${index + 1}. ${name}`);
			snippet.appendTabstop();

			if (index <= uris.length - 1 && uris.length > 1) {
				snippet.appendText('\n');
			}
		});

		//return new vscode.DocumentDropEdit(snippet);
		return new vscode.DocumentDropEdit(`testing drag
		n drop` );
	}
}
@VSCodeTriageBot
Copy link
Collaborator

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.88.0. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

@ajaygera
Copy link
Author

I am using latest vscode vesrion 1.88.0

@alexr00
Copy link
Member

alexr00 commented Apr 10, 2024

Not currently supported, but its a cool idea.

@alexr00 alexr00 added the feature-request Request for new features or functionality label Apr 10, 2024
@alexr00 alexr00 added this to the Backlog Candidates milestone Apr 10, 2024
@VSCodeTriageBot
Copy link
Collaborator

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@ajaygera
Copy link
Author

For drag and drop of vscode.TreeItem on editor , Can we implement vscode.DocumentDropEditProvider in order to insert custom data based on vscode.TreeItem?

@VSCodeTriageBot
Copy link
Collaborator

This feature request has not yet received the 20 community upvotes it takes to make to our backlog. 10 days to go. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@alexr00 alexr00 added the tree-views Extension tree view issues label May 31, 2024
@VSCodeTriageBot
Copy link
Collaborator

🙁 In the last 60 days, this feature request has received less than 20 community upvotes and we closed it. Still a big Thank You to you for taking the time to create this issue! To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@VSCodeTriageBot VSCodeTriageBot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality tree-views Extension tree view issues
Projects
None yet
Development

No branches or pull requests

3 participants