6
6
import * as path from 'path' ;
7
7
import * as vscode from 'vscode' ;
8
8
import * as URI from 'vscode-uri' ;
9
+ import { Schemes } from '../util/schemes' ;
9
10
10
11
const imageFileExtensions = new Set < string > ( [
11
12
'.bmp' ,
@@ -56,10 +57,12 @@ export async function tryGetUriListSnippet(document: vscode.TextDocument, dataTr
56
57
return ;
57
58
}
58
59
60
+ const docUri = getParentDocumentUri ( document ) ;
61
+
59
62
const snippet = new vscode . SnippetString ( ) ;
60
63
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, '/' ) )
63
66
: uri . toString ( false ) ;
64
67
65
68
const ext = URI . Utils . extname ( uri ) . toLowerCase ( ) ;
@@ -74,3 +77,17 @@ export async function tryGetUriListSnippet(document: vscode.TextDocument, dataTr
74
77
75
78
return snippet ;
76
79
}
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