| import * as path from 'path';
|
| import * as vscode from 'vscode';
|
|
|
| const uriListMime = 'text/uri-list';
|
|
|
| |
| |
| |
| |
| |
|
|
| class ReverseTextOnDropProvider implements vscode.DocumentDropEditProvider {
|
| async provideDocumentDropEdits(
|
| _document: vscode.TextDocument,
|
| position: vscode.Position,
|
| dataTransfer: vscode.DataTransfer,
|
| token: vscode.CancellationToken
|
| ): Promise<vscode.DocumentDropEdit | undefined> {
|
|
|
| const dataTransferItem = dataTransfer.get('text/plain');
|
| if (!dataTransferItem) {
|
| return undefined;
|
| }
|
|
|
| const text = await dataTransferItem.asString();
|
| if (token.isCancellationRequested) {
|
| return undefined;
|
| }
|
|
|
|
|
| const snippet = new vscode.SnippetString();
|
|
|
| snippet.appendText([...text].reverse().join(''));
|
|
|
| return new vscode.DocumentDropEdit(snippet);
|
| }
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| class FileNameListOnDropProvider implements vscode.DocumentDropEditProvider {
|
| async provideDocumentDropEdits(
|
| _document: vscode.TextDocument,
|
| _position: vscode.Position,
|
| dataTransfer: vscode.DataTransfer,
|
| token: vscode.CancellationToken
|
| ): Promise<vscode.DocumentDropEdit | undefined> {
|
|
|
| const dataTransferItem = dataTransfer.get(uriListMime);
|
| if (!dataTransferItem) {
|
| return undefined;
|
| }
|
|
|
|
|
|
|
| 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 {
|
|
|
| }
|
| }
|
|
|
| if (!uris.length) {
|
| return undefined;
|
| }
|
|
|
|
|
| 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);
|
| }
|
| }
|
|
|
|
|
| export function activate(context: vscode.ExtensionContext) {
|
|
|
| const selector: vscode.DocumentSelector = { language: 'plaintext' };
|
|
|
|
|
| context.subscriptions.push(vscode.languages.registerDocumentDropEditProvider(selector, new ReverseTextOnDropProvider()));
|
| context.subscriptions.push(vscode.languages.registerDocumentDropEditProvider(selector, new FileNameListOnDropProvider()));
|
| }
|
|
|