diff options
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/markdown-language-features/src/languageFeatures/copyPaste.ts | 14 | ||||
-rw-r--r-- | extensions/markdown-language-features/src/languageFeatures/dropIntoEditor.ts | 12 |
2 files changed, 18 insertions, 8 deletions
diff --git a/extensions/markdown-language-features/src/languageFeatures/copyPaste.ts b/extensions/markdown-language-features/src/languageFeatures/copyPaste.ts index d9e939b463c..c36403d06ee 100644 --- a/extensions/markdown-language-features/src/languageFeatures/copyPaste.ts +++ b/extensions/markdown-language-features/src/languageFeatures/copyPaste.ts @@ -4,23 +4,29 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; -import { tryInsertUriList } from './dropIntoEditor'; +import { tryGetUriListSnippet } from './dropIntoEditor'; export function registerPasteProvider(selector: vscode.DocumentSelector) { return vscode.languages.registerDocumentPasteEditProvider(selector, new class implements vscode.DocumentPasteEditProvider { async provideDocumentPasteEdits( document: vscode.TextDocument, - range: vscode.Range, + _ranges: readonly vscode.Range[], dataTransfer: vscode.DataTransfer, token: vscode.CancellationToken, - ): Promise<vscode.SnippetTextEdit | undefined> { + ): Promise<vscode.DocumentPasteEdit | undefined> { const enabled = vscode.workspace.getConfiguration('markdown', document).get('experimental.editor.pasteLinks.enabled', false); if (!enabled) { return; } - return tryInsertUriList(document, range, dataTransfer, token); + const snippet = await tryGetUriListSnippet(document, dataTransfer, token); + if (snippet) { + return { insertText: snippet }; + } + return undefined; } + }, { + pasteMimeTypes: ['text/uri-list'] }); } diff --git a/extensions/markdown-language-features/src/languageFeatures/dropIntoEditor.ts b/extensions/markdown-language-features/src/languageFeatures/dropIntoEditor.ts index 2ad71ec0516..b451ea40a4e 100644 --- a/extensions/markdown-language-features/src/languageFeatures/dropIntoEditor.ts +++ b/extensions/markdown-language-features/src/languageFeatures/dropIntoEditor.ts @@ -28,16 +28,20 @@ export function registerDropIntoEditor(selector: vscode.DocumentSelector) { async provideDocumentOnDropEdits(document: vscode.TextDocument, position: vscode.Position, dataTransfer: vscode.DataTransfer, token: vscode.CancellationToken): Promise<vscode.SnippetTextEdit | undefined> { const enabled = vscode.workspace.getConfiguration('markdown', document).get('editor.drop.enabled', true); if (!enabled) { - return; + return undefined; } const replacementRange = new vscode.Range(position, position); - return tryInsertUriList(document, replacementRange, dataTransfer, token); + const snippet = await tryGetUriListSnippet(document, dataTransfer, token); + if (snippet) { + return new vscode.SnippetTextEdit(replacementRange, snippet); + } + return undefined; } }); } -export async function tryInsertUriList(document: vscode.TextDocument, replacementRange: vscode.Range, dataTransfer: vscode.DataTransfer, token: vscode.CancellationToken): Promise<vscode.SnippetTextEdit | undefined> { +export async function tryGetUriListSnippet(document: vscode.TextDocument, dataTransfer: vscode.DataTransfer, token: vscode.CancellationToken): Promise<vscode.SnippetString | undefined> { const urlList = await dataTransfer.get('text/uri-list')?.asString(); if (!urlList || token.isCancellationRequested) { return undefined; @@ -72,5 +76,5 @@ export async function tryInsertUriList(document: vscode.TextDocument, replacemen } }); - return new vscode.SnippetTextEdit(replacementRange, snippet); + return snippet; } |