@@ -22,7 +22,7 @@ class DropOrPasteResourceProvider implements vscode.DocumentDropEditProvider, vs
22
22
return ;
23
23
}
24
24
25
- const snippet = await this . createUriListSnippet ( uriList ) ;
25
+ const snippet = await this . createUriListSnippet ( document . uri , uriList ) ;
26
26
if ( ! snippet || token . isCancellationRequested ) {
27
27
return ;
28
28
}
@@ -47,7 +47,7 @@ class DropOrPasteResourceProvider implements vscode.DocumentDropEditProvider, vs
47
47
return ;
48
48
}
49
49
50
- const snippet = await this . createUriListSnippet ( uriList ) ;
50
+ const snippet = await this . createUriListSnippet ( document . uri , uriList ) ;
51
51
if ( ! snippet || token . isCancellationRequested ) {
52
52
return ;
53
53
}
@@ -78,15 +78,15 @@ class DropOrPasteResourceProvider implements vscode.DocumentDropEditProvider, vs
78
78
return new UriList ( uris . map ( uri => ( { uri, str : uri . toString ( true ) } ) ) ) ;
79
79
}
80
80
81
- private async createUriListSnippet ( uriList : UriList ) : Promise < { readonly snippet : vscode . SnippetString ; readonly label : string } | undefined > {
81
+ private async createUriListSnippet ( docUri : vscode . Uri , uriList : UriList ) : Promise < { readonly snippet : vscode . SnippetString ; readonly label : string } | undefined > {
82
82
if ( ! uriList . entries . length ) {
83
83
return ;
84
84
}
85
85
86
86
const snippet = new vscode . SnippetString ( ) ;
87
87
for ( let i = 0 ; i < uriList . entries . length ; i ++ ) {
88
88
const uri = uriList . entries [ i ] ;
89
- const relativePath = getRelativePath ( uri . uri ) ;
89
+ const relativePath = getRelativePath ( getDocumentDir ( docUri ) , uri . uri ) ;
90
90
const urlText = relativePath ?? uri . str ;
91
91
92
92
snippet . appendText ( `url(${ urlText } )` ) ;
@@ -114,18 +114,17 @@ class DropOrPasteResourceProvider implements vscode.DocumentDropEditProvider, vs
114
114
}
115
115
}
116
116
117
- function getRelativePath ( file : vscode . Uri ) : string | undefined {
118
- const dir = getDocumentDir ( file ) ;
119
- if ( dir && dir . scheme === file . scheme && dir . authority === file . authority ) {
120
- if ( file . scheme === Schemes . file ) {
117
+ function getRelativePath ( fromFile : vscode . Uri | undefined , toFile : vscode . Uri ) : string | undefined {
118
+ if ( fromFile && fromFile . scheme === toFile . scheme && fromFile . authority === toFile . authority ) {
119
+ if ( toFile . scheme === Schemes . file ) {
121
120
// On windows, we must use the native `path.relative` to generate the relative path
122
121
// so that drive-letters are resolved cast insensitively. However we then want to
123
122
// convert back to a posix path to insert in to the document
124
- const relativePath = path . relative ( dir . fsPath , file . fsPath ) ;
123
+ const relativePath = path . relative ( fromFile . fsPath , toFile . fsPath ) ;
125
124
return path . posix . normalize ( relativePath . split ( path . sep ) . join ( path . posix . sep ) ) ;
126
125
}
127
126
128
- return path . posix . relative ( dir . path , file . path ) ;
127
+ return path . posix . relative ( fromFile . path , toFile . path ) ;
129
128
}
130
129
131
130
return undefined ;
0 commit comments