@@ -58,7 +58,10 @@ export class SaveAsSketch extends SketchContribution {
58
58
markAsRecentlyOpened,
59
59
} : SaveAsSketch . Options = SaveAsSketch . Options . DEFAULT
60
60
) : Promise < boolean > {
61
- const sketch = await this . sketchServiceClient . currentSketch ( ) ;
61
+ const [ sketch , configuration ] = await Promise . all ( [
62
+ this . sketchServiceClient . currentSketch ( ) ,
63
+ this . configService . getConfiguration ( ) ,
64
+ ] ) ;
62
65
if ( ! CurrentSketch . isValid ( sketch ) ) {
63
66
return false ;
64
67
}
@@ -68,15 +71,23 @@ export class SaveAsSketch extends SketchContribution {
68
71
return false ;
69
72
}
70
73
71
- // If target does not exist, propose a `directories.user`/${sketch.name} path
72
- // If target exists, propose `directories.user`/${sketch.name}_copy_${yyyymmddHHMMss}
73
- const sketchDirUri = new URI (
74
- ( await this . configService . getConfiguration ( ) ) . sketchDirUri
75
- ) ;
74
+ const sketchUri = new URI ( sketch . uri ) ;
75
+ const sketchbookDirUri = new URI ( configuration . sketchDirUri ) ;
76
+ // If the sketch is temp, IDE2 proposes the default sketchbook folder URI.
77
+ // If the sketch is not temp, but not contained in the default sketchbook folder, IDE2 proposes the default location.
78
+ // Otherwise, it proposes the parent folder of the current sketch.
79
+ const containerDirUri = isTemp
80
+ ? sketchbookDirUri
81
+ : ! sketchbookDirUri . isEqualOrParent ( sketchUri )
82
+ ? sketchbookDirUri
83
+ : sketchUri . parent ;
76
84
const exists = await this . fileService . exists (
77
- sketchDirUri . resolve ( sketch . name )
85
+ containerDirUri . resolve ( sketch . name )
78
86
) ;
79
- const defaultUri = sketchDirUri . resolve (
87
+
88
+ // If target does not exist, propose a `directories.user`/${sketch.name} path
89
+ // If target exists, propose `directories.user`/${sketch.name}_copy_${yyyymmddHHMMss}
90
+ const defaultUri = containerDirUri . resolve (
80
91
exists
81
92
? `${ sketch . name } _copy_${ dateFormat ( new Date ( ) , 'yyyymmddHHMMss' ) } `
82
93
: sketch . name
0 commit comments