From 0cfd46c14f67351db1e739834f58d8ed15d2bb4d Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Wed, 6 Sep 2023 07:01:56 +0200 Subject: Do not show (running) when opening picker (#8148) * only stream from background thread if necessary If the file transversal is longer shorter 30ms it will now be performed on the main thread. Spawning a thread can take a while (or rather it takes a while until that thread is scheduled) so the files can actually take a while to show up. This prevents the `(running)` indicator from briefly showing up when opening the file picker in a small directory. * run partial cargo update--- helix-term/src/ui/mod.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'helix-term/src/ui') diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index b2160108..12ac1783 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -190,7 +190,7 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> Picker .build() .expect("failed to build excluded_types"); walk_builder.types(excluded_types); - let files = walk_builder.build().filter_map(|entry| { + let mut files = walk_builder.build().filter_map(|entry| { let entry = entry.ok()?; if !entry.file_type()?.is_file() { return None; @@ -211,13 +211,27 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> Picker }) .with_preview(|_editor, path| Some((path.clone().into(), None))); let injector = picker.injector(); - std::thread::spawn(move || { - for file in files { - if injector.push(file).is_err() { - break; - } + let timeout = std::time::Instant::now() + std::time::Duration::from_millis(30); + + let mut hit_timeout = false; + for file in &mut files { + if injector.push(file).is_err() { + break; } - }); + if std::time::Instant::now() >= timeout { + hit_timeout = true; + break; + } + } + if hit_timeout { + std::thread::spawn(move || { + for file in files { + if injector.push(file).is_err() { + break; + } + } + }); + } picker } -- cgit v1.2.3-70-g09d2