@@ -908,12 +908,37 @@ define(function (require, exports, module) {
908908
909909 // filter folders using fuzzy matching
910910 const matches = folderList
911- . map ( folder => stringMatcher . match ( folder , query ) )
912- . filter ( result => result !== null && result !== undefined )
913- . sort ( ( a , b ) => b . matchGoodness - a . matchGoodness )
914- . slice ( 0 , 5 ) ;
911+ . map ( folder => {
912+ const result = stringMatcher . match ( folder , query ) ;
913+ if ( result ) {
914+ // get the last folder name (e.g., "assets/images/" -> "images")
915+ const folderPath = result . label || folder ;
916+ const segments = folderPath . split ( '/' ) . filter ( s => s . length > 0 ) ;
917+ const lastSegment = segments [ segments . length - 1 ] || '' ;
918+ result . folderName = lastSegment . toLowerCase ( ) ;
919+
920+ // we need to boost the score significantly if the last folder segment starts with the query
921+ // This ensures folders like "images/" rank higher than "testing/maps/google/" when typing "image"
922+ // note: here testing/maps/google has all the chars of 'image'
923+ if ( lastSegment . toLowerCase ( ) . startsWith ( query . toLowerCase ( ) ) ) {
924+ // Use a large positive boost (matchGoodness is negative, so we subtract a large negative number)
925+ result . matchGoodness -= 10000 ;
926+ }
927+ // Also boost (but less) if the last segment contains the query as a substring
928+ else if ( lastSegment . toLowerCase ( ) . includes ( query . toLowerCase ( ) ) ) {
929+ result . matchGoodness -= 1000 ;
930+ }
931+ }
932+ return result ;
933+ } )
934+ . filter ( result => result !== null && result !== undefined ) ;
935+
936+ // Sort by matchGoodness first (prefix matches will have best scores),
937+ // then alphabetically by folder name, then by full path
938+ StringMatch . multiFieldSort ( matches , { matchGoodness : 0 , folderName : 1 , label : 2 } ) ;
915939
916- _renderFolderSuggestions ( matches , $suggestions , $input ) ;
940+ const topMatches = matches . slice ( 0 , 5 ) ;
941+ _renderFolderSuggestions ( topMatches , $suggestions , $input ) ;
917942 }
918943
919944 /**
0 commit comments