@@ -1164,12 +1164,30 @@ define(function (require, exports, module) {
11641164 const shouldBeChecked = persistFolder !== false ;
11651165 $rememberCheckbox . prop ( 'checked' , shouldBeChecked ) ;
11661166
1167- _scanRootDirectoriesOnly ( projectRoot , rootFolders ) . then ( ( ) => {
1168- stringMatcher = new StringMatch . StringMatcher ( { segmentedSearch : true } ) ;
1169- _renderFolderSuggestions ( rootFolders . slice ( 0 , 15 ) , $suggestions , $input ) ;
1170- } ) ;
1167+ // check if any folder path exists, we pre-fill it
1168+ const savedFolder = StateManager . get ( IMAGE_DOWNLOAD_FOLDER_KEY , StateManager . PROJECT_CONTEXT ) ;
1169+ if ( savedFolder !== null && savedFolder !== undefined ) {
1170+ $input . val ( savedFolder ) ;
1171+ }
11711172
1172- _scanDirectories ( projectRoot , '' , folderList ) ;
1173+ // we only scan root directories if we don't have a pre-filled value
1174+ if ( ! savedFolder ) {
1175+ _scanRootDirectoriesOnly ( projectRoot , rootFolders ) . then ( ( ) => {
1176+ stringMatcher = new StringMatch . StringMatcher ( { segmentedSearch : true } ) ;
1177+ _renderFolderSuggestions ( rootFolders . slice ( 0 , 15 ) , $suggestions , $input ) ;
1178+ } ) ;
1179+ }
1180+
1181+ // scan all directories, and if we pre-filled a path, trigger autocomplete suggestions
1182+ _scanDirectories ( projectRoot , '' , folderList ) . then ( ( ) => {
1183+ // init stringMatcher if it wasn't created during root scan
1184+ if ( ! stringMatcher ) {
1185+ stringMatcher = new StringMatch . StringMatcher ( { segmentedSearch : true } ) ;
1186+ }
1187+ if ( savedFolder ) {
1188+ _updateFolderSuggestions ( savedFolder , folderList , rootFolders , stringMatcher , $suggestions , $input ) ;
1189+ }
1190+ } ) ;
11731191
11741192 // input event handler
11751193 $input . on ( 'input' , function ( ) {
@@ -1254,19 +1272,6 @@ define(function (require, exports, module) {
12541272 } ) ;
12551273 }
12561274
1257- /**
1258- * Handles reset of image folder selection - clears the saved preference and shows the dialog
1259- * @private
1260- */
1261- function _handleResetImageFolderSelection ( ) {
1262- // clear the saved folder preference for this project
1263- StateManager . set ( IMAGE_DOWNLOAD_FOLDER_KEY , null , StateManager . PROJECT_CONTEXT ) ;
1264-
1265- // show the folder selection dialog for the user to choose a new folder
1266- // we pass null because we're not downloading an image, just setting the preference
1267- _showFolderSelectionDialog ( null ) ;
1268- }
1269-
12701275 /**
12711276 * this function is responsible to save the active file (and previewed file, both might be same though)
12721277 * when ctrl/cmd + s is pressed in the live preview
@@ -1332,7 +1337,7 @@ define(function (require, exports, module) {
13321337
13331338 // handle reset image folder selection
13341339 if ( message . resetImageFolderSelection ) {
1335- _handleResetImageFolderSelection ( ) ;
1340+ _showFolderSelectionDialog ( null ) ;
13361341 return ;
13371342 }
13381343
0 commit comments