mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Auto create image links when dropping an image file into markdown
This commit is contained in:
parent
032ee47056
commit
62d6f38fc2
|
@ -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) ? '![' : '[');
|
||||
snippet.appendTabstop();
|
||||
snippet.appendText(`](${rel})`);
|
||||
|
||||
|
|
Loading…
Reference in a new issue