@@ -8,6 +8,7 @@ import * as nls from 'vscode-nls';
8
8
import { Command } from '../commandManager' ;
9
9
import { createUriListSnippet , getParentDocumentUri , imageFileExtensions } from '../languageFeatures/dropIntoEditor' ;
10
10
import { coalesce } from '../util/arrays' ;
11
+ import { Schemes } from '../util/schemes' ;
11
12
12
13
const localize = nls . loadMessageBundle ( ) ;
13
14
@@ -27,7 +28,7 @@ export class InsertLinkFromWorkspace implements Command {
27
28
canSelectMany : true ,
28
29
openLabel : localize ( 'insertLink.openLabel' , "Insert link" ) ,
29
30
title : localize ( 'insertLink.title' , "Insert link" ) ,
30
- defaultUri : getParentDocumentUri ( activeEditor . document ) ,
31
+ defaultUri : getDefaultUri ( activeEditor . document ) ,
31
32
} ) ;
32
33
33
34
return insertLink ( activeEditor , resources ?? [ ] , false ) ;
@@ -52,13 +53,21 @@ export class InsertImageFromWorkspace implements Command {
52
53
} ,
53
54
openLabel : localize ( 'insertImage.openLabel' , "Insert image" ) ,
54
55
title : localize ( 'insertImage.title' , "Insert image" ) ,
55
- defaultUri : getParentDocumentUri ( activeEditor . document ) ,
56
+ defaultUri : getDefaultUri ( activeEditor . document ) ,
56
57
} ) ;
57
58
58
59
return insertLink ( activeEditor , resources ?? [ ] , true ) ;
59
60
}
60
61
}
61
62
63
+ function getDefaultUri ( document : vscode . TextDocument ) {
64
+ const docUri = getParentDocumentUri ( document ) ;
65
+ if ( docUri . scheme === Schemes . untitled ) {
66
+ return vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri ;
67
+ }
68
+ return docUri ;
69
+ }
70
+
62
71
async function insertLink ( activeEditor : vscode . TextEditor , selectedFiles : vscode . Uri [ ] , insertAsImage : boolean ) : Promise < void > {
63
72
if ( ! selectedFiles . length ) {
64
73
return ;
0 commit comments