Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Links are not automatically pasted as Markdown link if nothing is selected #189338

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'; };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a future pr, try to move off of setting methods like this. Instead create a new instance of a document for each tests case

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