Skip to content

Commit

Permalink
Links are not automatically pasted as Markdown link if nothing is sel…
Browse files Browse the repository at this point in the history
…ected (#189338)

update automatic pasting
  • Loading branch information
MeghanKulkarni authored Jul 31, 2023
1 parent b670d63 commit f7d59ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f7d59ef

Please sign in to comment.