From 0a1504ff21ef67d187927c5606cfc993c8d303ad Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 15 Jul 2024 16:11:17 -0700 Subject: [PATCH] Finalize markdown update links on paste setting Fixes #209318 Enables this new feature by default (but as an option, not the default way to paste) --- extensions/markdown-language-features/package.json | 9 +++------ .../markdown-language-features/package.nls.json | 2 +- .../src/languageFeatures/updateLinksOnPaste.ts | 14 ++++++++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/extensions/markdown-language-features/package.json b/extensions/markdown-language-features/package.json index 7de963664c877..f06dd4233c87e 100644 --- a/extensions/markdown-language-features/package.json +++ b/extensions/markdown-language-features/package.json @@ -708,14 +708,11 @@ "%configuration.markdown.preferredMdPathExtensionStyle.removeExtension%" ] }, - "markdown.experimental.updateLinksOnPaste": { + "markdown.editor.updateLinksOnPaste.enabled": { "type": "boolean", - "default": false, - "markdownDescription": "%configuration.markdown.experimental.updateLinksOnPaste%", + "markdownDescription": "%configuration.markdown.editor.updateLinksOnPaste.enabled%", "scope": "resource", - "tags": [ - "experimental" - ] + "default": true } } }, diff --git a/extensions/markdown-language-features/package.nls.json b/extensions/markdown-language-features/package.nls.json index 3549ec58c517b..ba92cab47513c 100644 --- a/extensions/markdown-language-features/package.nls.json +++ b/extensions/markdown-language-features/package.nls.json @@ -91,6 +91,6 @@ "configuration.markdown.preferredMdPathExtensionStyle.removeExtension": "Prefer removing the file extension. For example, path completions to a file named `file.md` will insert `file` without the `.md`.", "configuration.markdown.editor.filePaste.videoSnippet": "Snippet used when adding videos to Markdown. This snippet can use the following variables:\n- `${src}` — The resolved path of the video file.\n- `${title}` — The title used for the video. A snippet placeholder will automatically be created for this variable.", "configuration.markdown.editor.filePaste.audioSnippet": "Snippet used when adding audio to Markdown. This snippet can use the following variables:\n- `${src}` — The resolved path of the audio file.\n- `${title}` — The title used for the audio. A snippet placeholder will automatically be created for this variable.", - "configuration.markdown.experimental.updateLinksOnPaste": "Enable/disable automatic updating of links in text that is copied and pasted from one Markdown editor to another.", + "configuration.markdown.editor.updateLinksOnPaste.enabled": "Enable/disable updating of links in text that is copied and pasted from one Markdown editor to another.", "workspaceTrust": "Required for loading styles configured in the workspace." } diff --git a/extensions/markdown-language-features/src/languageFeatures/updateLinksOnPaste.ts b/extensions/markdown-language-features/src/languageFeatures/updateLinksOnPaste.ts index 36b6eacfcfd4a..c8ad4c722fde8 100644 --- a/extensions/markdown-language-features/src/languageFeatures/updateLinksOnPaste.ts +++ b/extensions/markdown-language-features/src/languageFeatures/updateLinksOnPaste.ts @@ -9,7 +9,7 @@ import { Mime } from '../util/mimes'; class UpdatePastedLinksEditProvider implements vscode.DocumentPasteEditProvider { - public static readonly kind = vscode.DocumentDropOrPasteEditKind.Empty.append('text', 'markdown', 'updateLinks'); + public static readonly kind = vscode.DocumentDropOrPasteEditKind.Empty.append('markdown', 'updateLinks'); public static readonly metadataMime = 'vnd.vscode.markdown.updateLinksMetadata'; @@ -26,6 +26,7 @@ class UpdatePastedLinksEditProvider implements vscode.DocumentPasteEditProvider if (token.isCancellationRequested) { return; } + dataTransfer.set(UpdatePastedLinksEditProvider.metadataMime, new vscode.DataTransferItem(metadata)); } @@ -33,7 +34,7 @@ class UpdatePastedLinksEditProvider implements vscode.DocumentPasteEditProvider document: vscode.TextDocument, ranges: readonly vscode.Range[], dataTransfer: vscode.DataTransfer, - _context: vscode.DocumentPasteEditContext, + context: vscode.DocumentPasteEditContext, token: vscode.CancellationToken, ): Promise { if (!this._isEnabled(document)) { @@ -56,7 +57,7 @@ class UpdatePastedLinksEditProvider implements vscode.DocumentPasteEditProvider // - Copy with multiple cursors and paste into multiple locations // - ... const edits = await this._client.getUpdatePastedLinksEdit(document.uri, ranges.map(x => new vscode.TextEdit(x, text)), metadata, token); - if (!edits || !edits.length || token.isCancellationRequested) { + if (!edits?.length || token.isCancellationRequested) { return; } @@ -64,11 +65,16 @@ class UpdatePastedLinksEditProvider implements vscode.DocumentPasteEditProvider const workspaceEdit = new vscode.WorkspaceEdit(); workspaceEdit.set(document.uri, edits.map(x => new vscode.TextEdit(new vscode.Range(x.range.start.line, x.range.start.character, x.range.end.line, x.range.end.character,), x.newText))); pasteEdit.additionalEdit = workspaceEdit; + + if (!context.only || !UpdatePastedLinksEditProvider.kind.contains(context.only)) { + pasteEdit.yieldTo = [vscode.DocumentDropOrPasteEditKind.Empty.append('text')]; + } + return [pasteEdit]; } private _isEnabled(document: vscode.TextDocument): boolean { - return vscode.workspace.getConfiguration('markdown', document.uri).get('experimental.updateLinksOnPaste', false); + return vscode.workspace.getConfiguration('markdown', document.uri).get('editor.updateLinksOnPaste.enabled', true); } }