@@ -58,7 +58,10 @@ export class SaveAsSketch extends SketchContribution {
5858 markAsRecentlyOpened,
5959 } : SaveAsSketch . Options = SaveAsSketch . Options . DEFAULT
6060 ) : 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+ ] ) ;
6265 if ( ! CurrentSketch . isValid ( sketch ) ) {
6366 return false ;
6467 }
@@ -68,15 +71,23 @@ export class SaveAsSketch extends SketchContribution {
6871 return false ;
6972 }
7073
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 ;
7684 const exists = await this . fileService . exists (
77- sketchDirUri . resolve ( sketch . name )
85+ containerDirUri . resolve ( sketch . name )
7886 ) ;
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 (
8091 exists
8192 ? `${ sketch . name } _copy_${ dateFormat ( new Date ( ) , 'yyyymmddHHMMss' ) } `
8293 : sketch . name
0 commit comments