-
Notifications
You must be signed in to change notification settings - Fork 28k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
turning highlighted Markdown text to link to pasted URL (#185924)
* turning highlighted Mardown text to link to pasted URL * resolved comments * resolved more comments * preserved behavior of existing file pasting logic --------- Co-authored-by: Meghan Kulkarni <t-mekulkarni@microsoft.com>
- Loading branch information
1 parent
680cbcc
commit 6626f5f
Showing
9 changed files
with
142 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
extensions/markdown-language-features/src/languageFeatures/copyFiles/copyPasteLinks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import { getMarkdownLink } from './shared'; | ||
|
||
class PasteLinkEditProvider implements vscode.DocumentPasteEditProvider { | ||
|
||
private readonly _id = 'insertMarkdownLink'; | ||
async provideDocumentPasteEdits( | ||
document: vscode.TextDocument, | ||
ranges: readonly vscode.Range[], | ||
dataTransfer: vscode.DataTransfer, | ||
token: vscode.CancellationToken, | ||
): Promise<vscode.DocumentPasteEdit | undefined> { | ||
const enabled = vscode.workspace.getConfiguration('markdown', document).get('editor.pasteUrlAsFormattedLink.enabled', true); | ||
if (!enabled) { | ||
return; | ||
} | ||
|
||
// Check if dataTransfer contains a URL | ||
const item = dataTransfer.get('text/plain'); | ||
try { | ||
new URL(await item?.value); | ||
} catch (error) { | ||
return; | ||
} | ||
|
||
const label = vscode.l10n.t('Insert Markdown Link'); | ||
const uriEdit = new vscode.DocumentPasteEdit('', this._id, label); | ||
const urlList = await item?.asString(); | ||
if (!urlList) { | ||
return undefined; | ||
} | ||
const pasteEdit = await getMarkdownLink(document, ranges, urlList, token); | ||
if (!pasteEdit) { | ||
return; | ||
} | ||
|
||
uriEdit.additionalEdit = pasteEdit.additionalEdits; | ||
return uriEdit; | ||
} | ||
} | ||
|
||
export function registerLinkPasteSupport(selector: vscode.DocumentSelector,) { | ||
return vscode.languages.registerDocumentPasteEditProvider(selector, new PasteLinkEditProvider(), { | ||
pasteMimeTypes: [ | ||
'text/plain', | ||
] | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters