Skip to content

Commit f7d59ef

Browse files
Links are not automatically pasted as Markdown link if nothing is selected (microsoft#189338)
update automatic pasting
1 parent b670d63 commit f7d59ef

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

extensions/markdown-language-features/src/languageFeatures/copyFiles/shared.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ export async function createEditAddingLinksForUriList(
151151

152152
export function checkSmartPaste(document: SkinnyTextDocument, selectedRange: vscode.Range): SmartPaste {
153153
const SmartPaste: SmartPaste = { pasteAsMarkdownLink: true, updateTitle: false };
154+
if (selectedRange.isEmpty || /^[\s\n]*$/.test(document.getText(selectedRange))) {
155+
return { pasteAsMarkdownLink: false, updateTitle: false };
156+
}
154157
for (const regex of smartPasteRegexes) {
155158
const matches = [...document.getText().matchAll(regex.regex)];
156159
for (const match of matches) {

extensions/markdown-language-features/src/test/markdownLink.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,24 @@ suite('createEditAddingLinksForUriList', () => {
148148
};
149149

150150
test('Should evaluate pasteAsMarkdownLink as true for selected plain text', () => {
151-
const range = new vscode.Range(0, 5, 0, 5);
151+
const range = new vscode.Range(0, 0, 0, 12);
152152
const smartPaste = checkSmartPaste(skinnyDocument, range);
153153
assert.strictEqual(smartPaste.pasteAsMarkdownLink, true);
154154
});
155155

156+
test('Should evaluate pasteAsMarkdownLink as false for no selection', () => {
157+
const range = new vscode.Range(0, 0, 0, 0);
158+
const smartPaste = checkSmartPaste(skinnyDocument, range);
159+
assert.strictEqual(smartPaste.pasteAsMarkdownLink, false);
160+
});
161+
162+
test('Should evaluate pasteAsMarkdownLink as false for selected whitespace and new lines', () => {
163+
skinnyDocument.getText = function () { return ' \r\n\r\n'; };
164+
const range = new vscode.Range(0, 0, 0, 7);
165+
const smartPaste = checkSmartPaste(skinnyDocument, range);
166+
assert.strictEqual(smartPaste.pasteAsMarkdownLink, false);
167+
});
168+
156169
test('Should evaluate pasteAsMarkdownLink as false for pasting within a backtick code block', () => {
157170
skinnyDocument.getText = function () { return '```\r\n\r\n```'; };
158171
const range = new vscode.Range(0, 5, 0, 5);

0 commit comments

Comments
 (0)