mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-21 18:59:15 +00:00
Fix insert image/link for untitled files (#163897)
This commit is contained in:
@@ -8,6 +8,7 @@ import * as nls from 'vscode-nls';
|
||||
import { Command } from '../commandManager';
|
||||
import { createUriListSnippet, getParentDocumentUri, imageFileExtensions } from '../languageFeatures/dropIntoEditor';
|
||||
import { coalesce } from '../util/arrays';
|
||||
import { Schemes } from '../util/schemes';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@@ -27,7 +28,7 @@ export class InsertLinkFromWorkspace implements Command {
|
||||
canSelectMany: true,
|
||||
openLabel: localize('insertLink.openLabel', "Insert link"),
|
||||
title: localize('insertLink.title', "Insert link"),
|
||||
defaultUri: getParentDocumentUri(activeEditor.document),
|
||||
defaultUri: getDefaultUri(activeEditor.document),
|
||||
});
|
||||
|
||||
return insertLink(activeEditor, resources ?? [], false);
|
||||
@@ -52,13 +53,21 @@ export class InsertImageFromWorkspace implements Command {
|
||||
},
|
||||
openLabel: localize('insertImage.openLabel', "Insert image"),
|
||||
title: localize('insertImage.title', "Insert image"),
|
||||
defaultUri: getParentDocumentUri(activeEditor.document),
|
||||
defaultUri: getDefaultUri(activeEditor.document),
|
||||
});
|
||||
|
||||
return insertLink(activeEditor, resources ?? [], true);
|
||||
}
|
||||
}
|
||||
|
||||
function getDefaultUri(document: vscode.TextDocument) {
|
||||
const docUri = getParentDocumentUri(document);
|
||||
if (docUri.scheme === Schemes.untitled) {
|
||||
return vscode.workspace.workspaceFolders?.[0]?.uri;
|
||||
}
|
||||
return docUri;
|
||||
}
|
||||
|
||||
async function insertLink(activeEditor: vscode.TextEditor, selectedFiles: vscode.Uri[], insertAsImage: boolean): Promise<void> {
|
||||
if (!selectedFiles.length) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user