@@ -161,6 +161,27 @@ impl<T: Item> FilePicker<T> {
161
161
self . preview_cache . insert ( path. to_owned ( ) , preview) ;
162
162
Preview :: Cached ( & self . preview_cache [ path] )
163
163
}
164
+
165
+ fn handle_idle_timeout ( & mut self , cx : & mut Context ) -> EventResult {
166
+ // Try to find a document in the cache
167
+ let doc = self
168
+ . current_file ( cx. editor )
169
+ . and_then ( |( path, _range) | self . preview_cache . get_mut ( & path) )
170
+ . and_then ( |cache| match cache {
171
+ CachedPreview :: Document ( doc) => Some ( doc) ,
172
+ _ => None ,
173
+ } ) ;
174
+
175
+ // Then attempt to highlight it if it has no language set
176
+ if let Some ( doc) = doc {
177
+ if doc. language_config ( ) . is_none ( ) {
178
+ let loader = cx. editor . syn_loader . clone ( ) ;
179
+ doc. detect_language ( loader) ;
180
+ }
181
+ }
182
+
183
+ EventResult :: Consumed ( None )
184
+ }
164
185
}
165
186
166
187
impl < T : Item + ' static > Component for FilePicker < T > {
@@ -261,6 +282,9 @@ impl<T: Item + 'static> Component for FilePicker<T> {
261
282
}
262
283
263
284
fn handle_event ( & mut self , event : & Event , ctx : & mut Context ) -> EventResult {
285
+ if let Event :: IdleTimeout = event {
286
+ return self . handle_idle_timeout ( ctx) ;
287
+ }
264
288
// TODO: keybinds for scrolling preview
265
289
self . picker . handle_event ( event, ctx)
266
290
}
@@ -505,6 +529,9 @@ impl<T: Item + 'static> Component for Picker<T> {
505
529
compositor. last_picker = compositor. pop ( ) ;
506
530
} ) ) ) ;
507
531
532
+ // So that idle timeout retriggers
533
+ cx. editor . reset_idle_timer ( ) ;
534
+
508
535
match key_event {
509
536
shift ! ( Tab ) | key ! ( Up ) | ctrl ! ( 'p' ) => {
510
537
self . move_by ( 1 , Direction :: Backward ) ;
0 commit comments