Fix path sep for markdown drop on windows (#167862)

Fixes #167824
This commit is contained in:
Matt Bierner
2022-12-01 10:27:21 -08:00
committed by GitHub
parent 55d6b17e19
commit 9b3371e6e3

View File

@@ -103,10 +103,11 @@ export function createUriListSnippet(document: vscode.TextDocument, uris: readon
function getMdPath(dir: vscode.Uri | undefined, file: vscode.Uri) {
if (dir && dir.scheme === file.scheme && dir.authority === file.authority) {
if (file.scheme === Schemes.file) {
// On windows, we must use the native `path.resolve` to generate the relative path
// On windows, we must use the native `path.relative` to generate the relative path
// so that drive-letters are resolved cast insensitively. However we then want to
// convert back to a posix path to insert in to the document.
return encodeURI(path.posix.normalize(path.relative(dir.fsPath, file.fsPath)));
const relativePath = path.relative(dir.fsPath, file.fsPath);
return encodeURI(path.posix.normalize(relativePath.split(path.sep).join(path.posix.sep)));
}
return encodeURI(path.posix.relative(dir.path, file.path));