aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorPascal Kuthe2023-09-06 05:01:56 +0000
committerGitHub2023-09-06 05:01:56 +0000
commit0cfd46c14f67351db1e739834f58d8ed15d2bb4d (patch)
tree2fec405e4b4b780461b13a51c61f84904f2bb824 /helix-term
parent8778083b5a101947fb6d7c359772231a7610bf7a (diff)
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
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/ui/mod.rs28
1 files changed, 21 insertions, 7 deletions
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
}