Skip to content

Commit b731bee

Browse files
authored
Use notebook document uri for drop / copy paste (microsoft#157939)
Fixes microsoft#157938
1 parent 74f8a78 commit b731bee

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import * as path from 'path';
77
import * as vscode from 'vscode';
88
import * as URI from 'vscode-uri';
9+
import { Schemes } from '../util/schemes';
910

1011
const imageFileExtensions = new Set<string>([
1112
'.bmp',
@@ -56,10 +57,12 @@ export async function tryGetUriListSnippet(document: vscode.TextDocument, dataTr
5657
return;
5758
}
5859

60+
const docUri = getParentDocumentUri(document);
61+
5962
const snippet = new vscode.SnippetString();
6063
uris.forEach((uri, i) => {
61-
const mdPath = document.uri.scheme === uri.scheme
62-
? encodeURI(path.relative(URI.Utils.dirname(document.uri).fsPath, uri.fsPath).replace(/\\/g, '/'))
64+
const mdPath = docUri.scheme === uri.scheme && docUri.authority === uri.authority
65+
? encodeURI(path.relative(URI.Utils.dirname(docUri).fsPath, uri.fsPath).replace(/\\/g, '/'))
6366
: uri.toString(false);
6467

6568
const ext = URI.Utils.extname(uri).toLowerCase();
@@ -74,3 +77,17 @@ export async function tryGetUriListSnippet(document: vscode.TextDocument, dataTr
7477

7578
return snippet;
7679
}
80+
81+
function getParentDocumentUri(document: vscode.TextDocument): vscode.Uri {
82+
if (document.uri.scheme === Schemes.notebookCell) {
83+
for (const notebook of vscode.workspace.notebookDocuments) {
84+
for (const cell of notebook.getCells()) {
85+
if (cell.document === document) {
86+
return notebook.uri;
87+
}
88+
}
89+
}
90+
}
91+
92+
return document.uri;
93+
}

0 commit comments

Comments
 (0)