@@ -928,12 +928,38 @@ export class FolderMatchNoRoot extends FolderMatch {
928
928
* and their sort order is undefined.
929
929
*/
930
930
export function searchMatchComparer ( elementA : RenderableMatch , elementB : RenderableMatch , sortOrder : SearchSortOrder = SearchSortOrder . Default ) : number {
931
+
932
+ if ( elementA instanceof FileMatch && elementB instanceof FolderMatch ) {
933
+ return 1 ;
934
+ }
935
+
936
+ if ( elementB instanceof FileMatch && elementA instanceof FolderMatch ) {
937
+ return - 1 ;
938
+ }
939
+
931
940
if ( elementA instanceof FolderMatch && elementB instanceof FolderMatch ) {
932
941
const elemAIndex = elementA . index ( ) ;
933
942
const elemBIndex = elementB . index ( ) ;
934
943
if ( elemAIndex !== null && elemBIndex !== null ) {
935
944
return elemAIndex - elemBIndex ;
936
945
}
946
+
947
+ switch ( sortOrder ) {
948
+ case SearchSortOrder . CountDescending :
949
+ return elementB . count ( ) - elementA . count ( ) ;
950
+ case SearchSortOrder . CountAscending :
951
+ return elementA . count ( ) - elementB . count ( ) ;
952
+ case SearchSortOrder . Type :
953
+ return compareFileExtensions ( elementA . name ( ) , elementB . name ( ) ) ;
954
+ case SearchSortOrder . FileNames :
955
+ return compareFileNames ( elementA . name ( ) , elementB . name ( ) ) ;
956
+ // Fall through otherwise
957
+ default :
958
+ if ( ! elementA . resource || ! elementB . resource ) {
959
+ return 0 ;
960
+ }
961
+ return comparePaths ( elementA . resource . fsPath , elementB . resource . fsPath ) || compareFileNames ( elementA . name ( ) , elementB . name ( ) ) ;
962
+ }
937
963
}
938
964
939
965
if ( elementA instanceof FileMatch && elementB instanceof FileMatch ) {
@@ -947,12 +973,11 @@ export function searchMatchComparer(elementA: RenderableMatch, elementB: Rendera
947
973
case SearchSortOrder . FileNames :
948
974
return compareFileNames ( elementA . name ( ) , elementB . name ( ) ) ;
949
975
case SearchSortOrder . Modified : {
950
- if ( ! ( elementA instanceof FolderMatch ) || ! ( elementB instanceof FolderMatch ) ) {
951
- const fileStatA = elementA . fileStat ;
952
- const fileStatB = elementB . fileStat ;
953
- if ( fileStatA && fileStatB ) {
954
- return fileStatB . mtime - fileStatA . mtime ;
955
- }
976
+ const fileStatA = elementA . fileStat ;
977
+ const fileStatB = elementB . fileStat ;
978
+ if ( fileStatA && fileStatB ) {
979
+ return fileStatB . mtime - fileStatA . mtime ;
980
+
956
981
}
957
982
}
958
983
// Fall through otherwise
0 commit comments