@@ -885,6 +885,23 @@ define(function (require, exports, module) {
885885 } ) ;
886886 }
887887
888+ /**
889+ * this function is responsible to get the subdirectories inside a directory
890+ * we need this because we need to show the drilled down folders...
891+ * @param {String } parentPath - Parent folder path (e.g., "images/")
892+ * @param {Array<string> } folderList - Complete list of all folder paths
893+ * @return {Array<string> } Array of direct subfolders only
894+ */
895+ function _getSubfolders ( parentPath , folderList ) {
896+ return folderList . filter ( folder => {
897+ if ( ! folder . startsWith ( parentPath ) ) { return false ; }
898+
899+ const relativePath = folder . substring ( parentPath . length ) ;
900+ const pathWithoutTrailingSlash = relativePath . replace ( / \/ $ / , '' ) ;
901+ return ! pathWithoutTrailingSlash . includes ( '/' ) ;
902+ } ) ;
903+ }
904+
888905 /**
889906 * Renders folder suggestions as a dropdown in the UI with fuzzy match highlighting
890907 *
@@ -932,8 +949,7 @@ define(function (require, exports, module) {
932949 // when a suggestion is clicked we add the folder path in the input box
933950 $suggestions . find ( '.folder-suggestion-item' ) . on ( 'click' , function ( ) {
934951 const folderPath = $ ( this ) . data ( 'path' ) ;
935- $input . val ( folderPath ) ;
936- $suggestions . empty ( ) ;
952+ $input . val ( folderPath ) . trigger ( 'input' ) ;
937953 } ) ;
938954 }
939955
@@ -954,6 +970,18 @@ define(function (require, exports, module) {
954970 return ;
955971 }
956972
973+ // if the query ends with a /
974+ // we then show the drilled down list of dirs inside that parent directory
975+ if ( query . endsWith ( '/' ) ) {
976+ const subfolders = _getSubfolders ( query , folderList ) ;
977+ const formattedSubfolders = subfolders . map ( folder => {
978+ return stringMatcher . match ( folder , query ) || { label : folder , stringRanges : [ { text : folder , matched : false } ] } ;
979+ } ) ;
980+
981+ _renderFolderSuggestions ( formattedSubfolders . slice ( 0 , 15 ) , $suggestions , $input ) ;
982+ return ;
983+ }
984+
957985 if ( ! stringMatcher ) { return ; }
958986
959987 // filter folders using fuzzy matching
@@ -1048,8 +1076,7 @@ define(function (require, exports, module) {
10481076 // if there's a selected suggestion, use it
10491077 if ( $selected . length > 0 ) {
10501078 const folderPath = $selected . data ( 'path' ) ;
1051- $input . val ( folderPath ) ;
1052- $suggestions . empty ( ) ;
1079+ $input . val ( folderPath ) . trigger ( 'input' ) ;
10531080 } else {
10541081 // no suggestions, trigger OK button click
10551082 $dlg . find ( '[data-button-id="ok"]' ) . click ( ) ;
0 commit comments