mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-19 08:08:39 +01:00
Add commands to insert images/links in markdown (#163706)
* Add commands to insert images/links in markdown Fixes #162809 * Rename commands and allow passing in uris * Support selecting many images/files
This commit is contained in:
@@ -8,20 +8,20 @@ import * as vscode from 'vscode';
|
||||
import * as URI from 'vscode-uri';
|
||||
import { Schemes } from '../util/schemes';
|
||||
|
||||
const imageFileExtensions = new Set<string>([
|
||||
'.bmp',
|
||||
'.gif',
|
||||
'.ico',
|
||||
'.jpe',
|
||||
'.jpeg',
|
||||
'.jpg',
|
||||
'.png',
|
||||
'.psd',
|
||||
'.svg',
|
||||
'.tga',
|
||||
'.tif',
|
||||
'.tiff',
|
||||
'.webp',
|
||||
export const imageFileExtensions = new Set<string>([
|
||||
'bmp',
|
||||
'gif',
|
||||
'ico',
|
||||
'jpe',
|
||||
'jpeg',
|
||||
'jpg',
|
||||
'png',
|
||||
'psd',
|
||||
'svg',
|
||||
'tga',
|
||||
'tif',
|
||||
'tiff',
|
||||
'webp',
|
||||
]);
|
||||
|
||||
export function registerDropIntoEditorSupport(selector: vscode.DocumentSelector) {
|
||||
@@ -56,7 +56,20 @@ export async function tryGetUriListSnippet(document: vscode.TextDocument, dataTr
|
||||
return createUriListSnippet(document, uris);
|
||||
}
|
||||
|
||||
export function createUriListSnippet(document: vscode.TextDocument, uris: readonly vscode.Uri[]): vscode.SnippetString | undefined {
|
||||
interface UriListSnippetOptions {
|
||||
readonly placeholderText?: string;
|
||||
|
||||
readonly placeholderStartIndex?: number;
|
||||
|
||||
/**
|
||||
* Should the snippet be for an image?
|
||||
*
|
||||
* If `undefined`, tries to infer this from the uri.
|
||||
*/
|
||||
readonly insertAsImage?: boolean;
|
||||
}
|
||||
|
||||
export function createUriListSnippet(document: vscode.TextDocument, uris: readonly vscode.Uri[], options?: UriListSnippetOptions): vscode.SnippetString | undefined {
|
||||
if (!uris.length) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -69,9 +82,15 @@ export function createUriListSnippet(document: vscode.TextDocument, uris: readon
|
||||
? encodeURI(path.relative(dir.fsPath, uri.fsPath).replace(/\\/g, '/'))
|
||||
: uri.toString(false);
|
||||
|
||||
const ext = URI.Utils.extname(uri).toLowerCase();
|
||||
snippet.appendText(imageFileExtensions.has(ext) ? '`);
|
||||
|
||||
if (i <= uris.length - 1 && uris.length > 1) {
|
||||
@@ -89,7 +108,7 @@ function getDocumentDir(document: vscode.TextDocument): vscode.Uri | undefined {
|
||||
return URI.Utils.dirname(docUri);
|
||||
}
|
||||
|
||||
function getParentDocumentUri(document: vscode.TextDocument): vscode.Uri {
|
||||
export function getParentDocumentUri(document: vscode.TextDocument): vscode.Uri {
|
||||
if (document.uri.scheme === Schemes.notebookCell) {
|
||||
for (const notebook of vscode.workspace.notebookDocuments) {
|
||||
for (const cell of notebook.getCells()) {
|
||||
|
||||
Reference in New Issue
Block a user