Skip to content

Commit a62879b

Browse files
authored
Try computing windows paths correctly on markdown drop (microsoft#166077)
Fixes microsoft#165352
1 parent a74a764 commit a62879b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

extensions/markdown-language-features/src/languageFeatures/dropIntoEditor.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ export function createUriListSnippet(document: vscode.TextDocument, uris: readon
8080

8181
const snippet = new vscode.SnippetString();
8282
uris.forEach((uri, i) => {
83-
const mdPath = dir && dir.scheme === uri.scheme && dir.authority === uri.authority
84-
? encodeURI(path.posix.relative(dir.path, uri.path))
85-
: uri.toString(false);
83+
const mdPath = getMdPath(dir, uri);
8684

8785
const ext = URI.Utils.extname(uri).toLowerCase().replace('.', '');
8886
const insertAsImage = typeof options?.insertAsImage === 'undefined' ? imageFileExtensions.has(ext) : !!options.insertAsImage;
@@ -102,6 +100,21 @@ export function createUriListSnippet(document: vscode.TextDocument, uris: readon
102100
return snippet;
103101
}
104102

103+
function getMdPath(dir: vscode.Uri | undefined, file: vscode.Uri) {
104+
if (dir && dir.scheme === file.scheme && dir.authority === file.authority) {
105+
if (file.scheme === Schemes.file) {
106+
// On windows, we must use the native `path.resolve` to generate the relative path
107+
// so that drive-letters are resolved cast insensitively. However we then want to
108+
// convert back to a posix path to insert in to the document.
109+
return encodeURI(path.posix.normalize(path.relative(dir.fsPath, file.fsPath)));
110+
}
111+
112+
return encodeURI(path.posix.relative(dir.path, file.path));
113+
}
114+
115+
return file.toString(false);
116+
}
117+
105118
function getDocumentDir(document: vscode.TextDocument): vscode.Uri | undefined {
106119
const docUri = getParentDocumentUri(document);
107120
if (docUri.scheme === Schemes.untitled) {

0 commit comments

Comments
 (0)