Skip to content

Commit

Permalink
Do not show (running) when opening picker (helix-editor#8148)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pascalkuthe authored and dgkf committed Jan 30, 2024
1 parent f4c24ea commit 441786c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 45 deletions.
49 changes: 11 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 21 additions & 7 deletions helix-term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
}

Expand Down

0 comments on commit 441786c

Please sign in to comment.