Skip to content

Commit

Permalink
always check if a search is active when rescanning (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
ToBinio authored Jan 14, 2025
1 parent 1996325 commit 59ea01f
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ impl App {
Task::batch([
self.update_title(),
self.update_watcher(),
self.rescan_tab(entity, location, selection_paths),
self.update_tab(entity, location, selection_paths),
]),
)
}
Expand Down Expand Up @@ -829,7 +829,20 @@ impl App {
return Task::none();
}
}
self.rescan_tab(entity, tab.location.clone(), Some(op_sel.selected))
self.update_tab(entity, tab.location.clone(), Some(op_sel.selected))
}

fn update_tab(
&mut self,
entity: Entity,
location: Location,
selection_paths: Option<Vec<PathBuf>>,
) -> Task<Message> {
if let Location::Search(_, term, ..) = location {
self.search_set(entity, Some(term), selection_paths)
} else {
self.rescan_tab(entity, location, selection_paths)
}
}

fn rescan_tab(
Expand Down Expand Up @@ -873,19 +886,11 @@ impl App {

let mut commands = Vec::with_capacity(needs_reload.len());
for (entity, location) in needs_reload {
commands.push(self.rescan_tab(entity, location, None));
commands.push(self.update_tab(entity, location, None));
}
Task::batch(commands)
}

fn search(&mut self) -> Task<Message> {
if let Some(term) = self.search_get() {
self.search_set_active(Some(term.to_string()))
} else {
Task::none()
}
}

fn search_get(&self) -> Option<&str> {
let entity = self.tab_model.active();
let tab = self.tab_model.data::<Tab>(entity)?;
Expand All @@ -897,10 +902,15 @@ impl App {

fn search_set_active(&mut self, term_opt: Option<String>) -> Task<Message> {
let entity = self.tab_model.active();
self.search_set(entity, term_opt)
self.search_set(entity, term_opt, None)
}

fn search_set(&mut self, tab: Entity, term_opt: Option<String>) -> Task<Message> {
fn search_set(
&mut self,
tab: Entity,
term_opt: Option<String>,
selection_paths: Option<Vec<PathBuf>>,
) -> Task<Message> {
let mut title_location_opt = None;
if let Some(tab) = self.tab_model.data_mut::<Tab>(tab) {
let location_opt = match term_opt {
Expand Down Expand Up @@ -931,7 +941,7 @@ impl App {
return Task::batch([
self.update_title(),
self.update_watcher(),
self.rescan_tab(tab, location, None),
self.rescan_tab(tab, location, selection_paths),
if focus_search {
widget::text_input::focus(self.search_id.clone())
} else {
Expand Down Expand Up @@ -990,7 +1000,7 @@ impl App {
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
tab.location = location.clone();
}
commands.push(self.rescan_tab(entity, location, None));
commands.push(self.update_tab(entity, location, None));
}
Task::batch(commands)
}
Expand Down Expand Up @@ -2139,7 +2149,7 @@ impl Application for App {
};
if let Some(title) = title_opt {
self.tab_model.text_set(entity, title);
commands.push(self.rescan_tab(entity, home_location.clone(), None));
commands.push(self.update_tab(entity, home_location.clone(), None));
}
}
if !commands.is_empty() {
Expand Down Expand Up @@ -2304,11 +2314,7 @@ impl Application for App {

let mut commands = Vec::with_capacity(needs_reload.len());
for (entity, location) in needs_reload {
if let Location::Search(_, term, ..) = location {
commands.push(self.search_set(entity, Some(term)));
} else {
commands.push(self.rescan_tab(entity, location, None));
}
commands.push(self.update_tab(entity, location, None));
}
return Task::batch(commands);
}
Expand Down Expand Up @@ -2547,8 +2553,6 @@ impl Application for App {
commands.push(self.rescan_operation_selection(op_sel));
// Manually rescan any trash tabs after any operation is completed
commands.push(self.rescan_trash());
// if search is active, update "search" tab view
commands.push(self.search());
return Task::batch(commands);
}
Message::PendingDismiss => {
Expand Down Expand Up @@ -2871,7 +2875,7 @@ impl Application for App {
commands.push(Task::batch([
self.update_title(),
self.update_watcher(),
self.rescan_tab(entity, tab_path, selection_paths),
self.update_tab(entity, tab_path, selection_paths),
]));
}
tab::Command::DropFiles(to, from) => {
Expand Down Expand Up @@ -3164,7 +3168,7 @@ impl Application for App {
return Task::batch([
self.update_title(),
self.update_watcher(),
self.rescan_tab(entity, location, None),
self.update_tab(entity, location, None),
]);
}
}
Expand Down

0 comments on commit 59ea01f

Please sign in to comment.