You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
}
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` );
}
}
The text was updated successfully, but these errors were encountered:
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.
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.
For drag and drop of vscode.TreeItem on editor , Can we implement vscode.DocumentDropEditProvider in order to insert custom data based on vscode.TreeItem?
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.
🙁 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.
Does this issue occur when all extensions are disabled?: Yes/No
Steps to Reproduce:
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 \
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.
The text was updated successfully, but these errors were encountered: