Skip to content

Commit a85e386

Browse files
committed
picker: Highlight the document on idle timeout
1 parent 001858b commit a85e386

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

helix-term/src/ui/picker.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,27 @@ impl<T: Item> FilePicker<T> {
161161
self.preview_cache.insert(path.to_owned(), preview);
162162
Preview::Cached(&self.preview_cache[path])
163163
}
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+
}
164185
}
165186

166187
impl<T: Item + 'static> Component for FilePicker<T> {
@@ -261,6 +282,9 @@ impl<T: Item + 'static> Component for FilePicker<T> {
261282
}
262283

263284
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+
}
264288
// TODO: keybinds for scrolling preview
265289
self.picker.handle_event(event, ctx)
266290
}
@@ -505,6 +529,9 @@ impl<T: Item + 'static> Component for Picker<T> {
505529
compositor.last_picker = compositor.pop();
506530
})));
507531

532+
// So that idle timeout retriggers
533+
cx.editor.reset_idle_timer();
534+
508535
match key_event {
509536
shift!(Tab) | key!(Up) | ctrl!('p') => {
510537
self.move_by(1, Direction::Backward);

0 commit comments

Comments
 (0)