mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 00:28:52 +01:00
Switch to provider based model for on drop
This simplifies implementing the provider and also give potentially gives us more control over how the drop happens
This commit is contained in:
@@ -7,10 +7,10 @@ import * as path from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
import * as URI from 'vscode-uri';
|
||||
|
||||
export function registerDropIntoEditor() {
|
||||
return vscode.workspace.onWillDropOnTextEditor(e => {
|
||||
e.waitUntil((async (): Promise<vscode.SnippetTextEdit | undefined> => {
|
||||
const urlList = await e.dataTransfer.get('text/uri-list')?.asString();
|
||||
export function registerDropIntoEditor(selector: vscode.DocumentSelector) {
|
||||
return vscode.languages.registerDocumentOnDropProvider(selector, new class implements vscode.DocumentOnDropProvider {
|
||||
async provideDocumentOnDropEdits(document: vscode.TextDocument, position: vscode.Position, dataTransfer: vscode.DataTransfer, _token: vscode.CancellationToken): Promise<vscode.SnippetTextEdit | undefined> {
|
||||
const urlList = await dataTransfer.get('text/uri-list')?.asString();
|
||||
if (!urlList) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ export function registerDropIntoEditor() {
|
||||
|
||||
const snippet = new vscode.SnippetString();
|
||||
uris.forEach((uri, i) => {
|
||||
const rel = path.relative(URI.Utils.dirname(e.editor.document.uri).fsPath, uri.fsPath);
|
||||
const rel = path.relative(URI.Utils.dirname(document.uri).fsPath, uri.fsPath);
|
||||
|
||||
snippet.appendText('[');
|
||||
snippet.appendTabstop();
|
||||
@@ -41,7 +41,7 @@ export function registerDropIntoEditor() {
|
||||
}
|
||||
});
|
||||
|
||||
return new vscode.SnippetTextEdit(new vscode.Range(e.position, e.position), snippet);
|
||||
})());
|
||||
return new vscode.SnippetTextEdit(new vscode.Range(position, position), snippet);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user