Skip to content

Commit

Permalink
Support toggling hidden files in search
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Oct 10, 2024
1 parent f2e207b commit 28b4dda
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 37 deletions.
7 changes: 6 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,12 @@ impl App {
let location_opt = match term_opt {
Some(term) => match &tab.location {
Location::Path(path) | Location::Search(path, ..) => Some((
Location::Search(path.to_path_buf(), term, Instant::now()),
Location::Search(
path.to_path_buf(),
term,
tab.config.show_hidden,
Instant::now(),
),
true,
)),
_ => None,
Expand Down
7 changes: 6 additions & 1 deletion src/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,12 @@ impl App {
let location_opt = match term_opt {
Some(term) => match &self.tab.location {
Location::Path(path) | Location::Search(path, ..) => Some((
Location::Search(path.to_path_buf(), term, Instant::now()),
Location::Search(
path.to_path_buf(),
term,
self.tab.config.show_hidden,
Instant::now(),
),
true,
)),
_ => None,
Expand Down
90 changes: 55 additions & 35 deletions src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ pub fn scan_path(tab_path: &PathBuf, sizes: IconSizes) -> Vec<Item> {
pub fn scan_search<F: Fn(&Path, &str, Metadata) -> bool + Sync>(
tab_path: &PathBuf,
term: &str,
show_hidden: bool,
callback: F,
) {
if term.is_empty() {
Expand All @@ -551,8 +552,9 @@ pub fn scan_search<F: Fn(&Path, &str, Metadata) -> bool + Sync>(
}
};

//TODO: do we want to ignore files?
ignore::WalkBuilder::new(tab_path)
.standard_filters(false)
.hidden(!show_hidden)
//TODO: only use this on supported targets
.same_file_system(true)
.build_parallel()
Expand Down Expand Up @@ -864,7 +866,7 @@ pub enum Location {
Network(String, String),
Path(PathBuf),
Recents,
Search(PathBuf, String, Instant),
Search(PathBuf, String, bool, Instant),
Trash,
}

Expand Down Expand Up @@ -899,7 +901,9 @@ impl Location {
Self::Desktop(path, display.clone(), *desktop_config)
}
Self::Path(..) => Self::Path(path),
Self::Search(_, term, ..) => Self::Search(path, term.clone(), Instant::now()),
Self::Search(_, term, show_hidden, _) => {
Self::Search(path, term.clone(), *show_hidden, Instant::now())
}
other => other.clone(),
}
}
Expand Down Expand Up @@ -2580,8 +2584,17 @@ impl Tab {
}
}
}
Message::ToggleShowHidden => self.config.show_hidden = !self.config.show_hidden,

Message::ToggleShowHidden => {
self.config.show_hidden = !self.config.show_hidden;
if let Location::Search(path, term, ..) = &self.location {
cd = Some(Location::Search(
path.clone(),
term.clone(),
self.config.show_hidden,
Instant::now(),
));
}
}
Message::View(view) => {
self.config.view = view;
}
Expand Down Expand Up @@ -4194,10 +4207,11 @@ impl Tab {
}

// Load search items incrementally
if let Location::Search(path, term, start) = &self.location {
if let Location::Search(path, term, show_hidden, start) = &self.location {
let location = self.location.clone();
let path = path.clone();
let term = term.clone();
let show_hidden = *show_hidden;
let start = start.clone();
subscriptions.push(subscription::channel(
location.clone(),
Expand All @@ -4224,41 +4238,47 @@ impl Tab {
{
let output = output.clone();
tokio::task::spawn_blocking(move || {
scan_search(&path, &term, move |path, name, metadata| -> bool {
// Don't send if the result is too old
if let Some(last_modified) = *last_modified_opt.read().unwrap() {
if let Ok(modified) = metadata.modified() {
if metadata.modified().ok() < Some(last_modified) {
scan_search(
&path,
&term,
show_hidden,
move |path, name, metadata| -> bool {
// Don't send if the result is too old
if let Some(last_modified) = *last_modified_opt.read().unwrap()
{
if let Ok(modified) = metadata.modified() {
if modified < last_modified {
return true;
}
} else {
return true;
}
} else {
return true;
}
}

match results_tx.blocking_send((
path.to_path_buf(),
name.to_string(),
metadata,
)) {
Ok(()) => {
if !ready.swap(true, atomic::Ordering::SeqCst) {
// Wake up update method
futures::executor::block_on(async {
output
.lock()
.await
.send(Message::SearchReady(false))
.await
})
.is_ok()
} else {
true
match results_tx.blocking_send((
path.to_path_buf(),
name.to_string(),
metadata,
)) {
Ok(()) => {
if !ready.swap(true, atomic::Ordering::SeqCst) {
// Wake up update method
futures::executor::block_on(async {
output
.lock()
.await
.send(Message::SearchReady(false))
.await
})
.is_ok()
} else {
true
}
}
Err(_) => false,
}
Err(_) => false,
}
});
},
);
log::info!(
"searched for {:?} in {:?} in {:?}",
term,
Expand Down

0 comments on commit 28b4dda

Please sign in to comment.