on master help sign in
picker: Highlight the document on idle timeout
commita85e3862988933953d1c0e7435969604d3722959 authorBlaž Hrastnik <blaz@mxxn.io> dateTue 11 Oct 2022, 09:53 (4 years ago) parent001858b
1 file changed+27
helix-term/src/ui/picker.rs+27
helix-term/src/ui/picker.rs+27
@@ -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
166187impl<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);