@@ -131,7 +131,6 @@ export class FilesCollector {
131131 now : number ,
132132 three_hours : number
133133 ) : string [ ] {
134- // Categorize files into two groups
135134 const recently_modified : Array < { path : string ; mtime : number } > = [ ]
136135 const older_files : Array < { path : string ; timestamp : number } > = [ ]
137136
@@ -146,10 +145,8 @@ export class FilesCollector {
146145 this . workspace_provider . get_selection_timestamp ( file_path ) ?? now
147146
148147 if ( now - mtime < three_hours ) {
149- // Modified within last 3 hours
150148 recently_modified . push ( { path : file_path , mtime } )
151149 } else {
152- // Modified earlier than 3 hours
153150 older_files . push ( { path : file_path , timestamp : selection_timestamp } )
154151 }
155152 } catch ( error ) {
@@ -158,19 +155,20 @@ export class FilesCollector {
158155 }
159156
160157 // Sort older files by selection timestamp (ascending), with natural sort as tiebreaker
158+ // Files selected within 20 seconds of each other are grouped and sorted naturally
161159 older_files . sort ( ( a , b ) => {
162- const timestamp_diff = a . timestamp - b . timestamp
163- if ( timestamp_diff != 0 ) {
164- return timestamp_diff
160+ const timestamp_bucket_a = Math . floor ( a . timestamp / 20 )
161+ const timestamp_bucket_b = Math . floor ( b . timestamp / 20 )
162+ const bucket_diff = timestamp_bucket_a - timestamp_bucket_b
163+ if ( bucket_diff != 0 ) {
164+ return bucket_diff
165165 }
166- // If timestamps are the same, use natural sort on paths
166+ // If timestamps are within the same 20-second bucket , use natural sort on paths
167167 return natural_sort ( a . path , b . path )
168168 } )
169169
170- // Sort recently modified files by modification time (ascending - oldest to newest)
171170 recently_modified . sort ( ( a , b ) => a . mtime - b . mtime )
172171
173- // Combine: older files first, then recently modified
174172 return [
175173 ...older_files . map ( ( f ) => f . path ) ,
176174 ...recently_modified . map ( ( f ) => f . path )
0 commit comments