diff --git a/extensions/markdown-language-features/src/languageFeatures/copyFiles/shared.ts b/extensions/markdown-language-features/src/languageFeatures/copyFiles/shared.ts index 768fafded3d33..082f569b0b102 100644 --- a/extensions/markdown-language-features/src/languageFeatures/copyFiles/shared.ts +++ b/extensions/markdown-language-features/src/languageFeatures/copyFiles/shared.ts @@ -151,6 +151,9 @@ export async function createEditAddingLinksForUriList( export function checkSmartPaste(document: SkinnyTextDocument, selectedRange: vscode.Range): SmartPaste { const SmartPaste: SmartPaste = { pasteAsMarkdownLink: true, updateTitle: false }; + if (selectedRange.isEmpty || /^[\s\n]*$/.test(document.getText(selectedRange))) { + return { pasteAsMarkdownLink: false, updateTitle: false }; + } for (const regex of smartPasteRegexes) { const matches = [...document.getText().matchAll(regex.regex)]; for (const match of matches) { diff --git a/extensions/markdown-language-features/src/test/markdownLink.test.ts b/extensions/markdown-language-features/src/test/markdownLink.test.ts index bf7e82b439c97..05a08b1046340 100644 --- a/extensions/markdown-language-features/src/test/markdownLink.test.ts +++ b/extensions/markdown-language-features/src/test/markdownLink.test.ts @@ -148,11 +148,24 @@ suite('createEditAddingLinksForUriList', () => { }; test('Should evaluate pasteAsMarkdownLink as true for selected plain text', () => { - const range = new vscode.Range(0, 5, 0, 5); + const range = new vscode.Range(0, 0, 0, 12); const smartPaste = checkSmartPaste(skinnyDocument, range); assert.strictEqual(smartPaste.pasteAsMarkdownLink, true); }); + test('Should evaluate pasteAsMarkdownLink as false for no selection', () => { + const range = new vscode.Range(0, 0, 0, 0); + const smartPaste = checkSmartPaste(skinnyDocument, range); + assert.strictEqual(smartPaste.pasteAsMarkdownLink, false); + }); + + test('Should evaluate pasteAsMarkdownLink as false for selected whitespace and new lines', () => { + skinnyDocument.getText = function () { return ' \r\n\r\n'; }; + const range = new vscode.Range(0, 0, 0, 7); + const smartPaste = checkSmartPaste(skinnyDocument, range); + assert.strictEqual(smartPaste.pasteAsMarkdownLink, false); + }); + test('Should evaluate pasteAsMarkdownLink as false for pasting within a backtick code block', () => { skinnyDocument.getText = function () { return '```\r\n\r\n```'; }; const range = new vscode.Range(0, 5, 0, 5);