mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 00:28:52 +01:00
Auto create image links when dropping an image file into markdown
This commit is contained in:
@@ -7,6 +7,22 @@ import * as path from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
import * as URI from 'vscode-uri';
|
||||
|
||||
const imageFileExtensions = new Set<string>([
|
||||
'.bmp',
|
||||
'.gif',
|
||||
'.ico',
|
||||
'.jpe',
|
||||
'.jpeg',
|
||||
'.jpg',
|
||||
'.png',
|
||||
'.psd',
|
||||
'.svg',
|
||||
'.tga',
|
||||
'.tif',
|
||||
'.tiff',
|
||||
'.webp',
|
||||
]);
|
||||
|
||||
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> {
|
||||
@@ -37,7 +53,8 @@ export function registerDropIntoEditor(selector: vscode.DocumentSelector) {
|
||||
uris.forEach((uri, i) => {
|
||||
const rel = path.relative(URI.Utils.dirname(document.uri).fsPath, uri.fsPath);
|
||||
|
||||
snippet.appendText('[');
|
||||
const ext = URI.Utils.extname(uri).toLowerCase();
|
||||
snippet.appendText(imageFileExtensions.has(ext) ? '`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user