mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 04:09:28 +00:00
Drop into text editor api proposal (#143334)
* Add drop into editor api proposal For #142990 * Use AsyncEmitter
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as path from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
import * as URI from 'vscode-uri';
|
||||
import { CommandManager } from './commandManager';
|
||||
import * as commands from './commands/index';
|
||||
import LinkProvider from './features/documentLinkProvider';
|
||||
@@ -45,6 +47,43 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
logger.updateConfiguration();
|
||||
previewManager.updateConfiguration();
|
||||
}));
|
||||
|
||||
context.subscriptions.push(vscode.workspace.onWillDropOnTextEditor(e => {
|
||||
e.waitUntil((async () => {
|
||||
const resourceUrls = await e.dataTransfer.get('resourceurls')?.asString();
|
||||
if (!resourceUrls) {
|
||||
return;
|
||||
}
|
||||
|
||||
const uris: vscode.Uri[] = [];
|
||||
for (const resource of JSON.parse(resourceUrls)) {
|
||||
try {
|
||||
uris.push(vscode.Uri.parse(resource));
|
||||
} catch {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
|
||||
if (!uris.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const snippet = new vscode.SnippetString();
|
||||
uris.forEach((uri, i) => {
|
||||
const rel = path.relative(URI.Utils.dirname(e.editor.document.uri).fsPath, uri.fsPath);
|
||||
|
||||
snippet.appendText('[');
|
||||
snippet.appendTabstop();
|
||||
snippet.appendText(`](${rel})`);
|
||||
|
||||
if (i <= uris.length - 1 && uris.length > 1) {
|
||||
snippet.appendText(' ');
|
||||
}
|
||||
});
|
||||
|
||||
return e.editor.insertSnippet(snippet, e.position);
|
||||
})());
|
||||
}));
|
||||
}
|
||||
|
||||
function registerMarkdownLanguageFeatures(
|
||||
|
||||
Reference in New Issue
Block a user