@@ -893,12 +893,37 @@ define(function (require, exports, module) {
893893
894894 // filter folders using fuzzy matching
895895 const matches = folderList
896- . map ( folder => stringMatcher . match ( folder , query ) )
897- . filter ( result => result !== null && result !== undefined )
898- . sort ( ( a , b ) => b . matchGoodness - a . matchGoodness )
899- . slice ( 0 , 5 ) ;
896+ . map ( folder => {
897+ const result = stringMatcher . match ( folder , query ) ;
898+ if ( result ) {
899+ // get the last folder name (e.g., "assets/images/" -> "images")
900+ const folderPath = result . label || folder ;
901+ const segments = folderPath . split ( '/' ) . filter ( s => s . length > 0 ) ;
902+ const lastSegment = segments [ segments . length - 1 ] || '' ;
903+ result . folderName = lastSegment . toLowerCase ( ) ;
904+
905+ // we need to boost the score significantly if the last folder segment starts with the query
906+ // This ensures folders like "images/" rank higher than "testing/maps/google/" when typing "image"
907+ // note: here testing/maps/google has all the chars of 'image'
908+ if ( lastSegment . toLowerCase ( ) . startsWith ( query . toLowerCase ( ) ) ) {
909+ // Use a large positive boost (matchGoodness is negative, so we subtract a large negative number)
910+ result . matchGoodness -= 10000 ;
911+ }
912+ // Also boost (but less) if the last segment contains the query as a substring
913+ else if ( lastSegment . toLowerCase ( ) . includes ( query . toLowerCase ( ) ) ) {
914+ result . matchGoodness -= 1000 ;
915+ }
916+ }
917+ return result ;
918+ } )
919+ . filter ( result => result !== null && result !== undefined ) ;
920+
921+ // Sort by matchGoodness first (prefix matches will have best scores),
922+ // then alphabetically by folder name, then by full path
923+ StringMatch . multiFieldSort ( matches , { matchGoodness : 0 , folderName : 1 , label : 2 } ) ;
900924
901- _renderFolderSuggestions ( matches , $suggestions , $input ) ;
925+ const topMatches = matches . slice ( 0 , 5 ) ;
926+ _renderFolderSuggestions ( topMatches , $suggestions , $input ) ;
902927 }
903928
904929 /**
0 commit comments