Merge pull request #711 from ToBinio/update-search
fix: update search on events
This commit is contained in:
commit
9f819454ae
1 changed files with 46 additions and 38 deletions
26
src/app.rs
26
src/app.rs
|
|
@ -879,7 +879,7 @@ impl App {
|
||||||
|
|
||||||
fn search(&mut self) -> Task<Message> {
|
fn search(&mut self) -> Task<Message> {
|
||||||
if let Some(term) = self.search_get() {
|
if let Some(term) = self.search_get() {
|
||||||
self.search_set(Some(term.to_string()))
|
self.search_set_active(Some(term.to_string()))
|
||||||
} else {
|
} else {
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
@ -894,10 +894,14 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_set(&mut self, term_opt: Option<String>) -> Task<Message> {
|
fn search_set_active(&mut self, term_opt: Option<String>) -> Task<Message> {
|
||||||
let entity = self.tab_model.active();
|
let entity = self.tab_model.active();
|
||||||
|
self.search_set(entity, term_opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn search_set(&mut self,tab: Entity, term_opt: Option<String>) -> Task<Message> {
|
||||||
let mut title_location_opt = None;
|
let mut title_location_opt = None;
|
||||||
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
|
if let Some(tab) = self.tab_model.data_mut::<Tab>(tab) {
|
||||||
let location_opt = match term_opt {
|
let location_opt = match term_opt {
|
||||||
Some(term) => match &tab.location {
|
Some(term) => match &tab.location {
|
||||||
Location::Path(path) | Location::Search(path, ..) => Some((
|
Location::Path(path) | Location::Search(path, ..) => Some((
|
||||||
|
|
@ -922,11 +926,11 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some((title, location, focus_search)) = title_location_opt {
|
if let Some((title, location, focus_search)) = title_location_opt {
|
||||||
self.tab_model.text_set(entity, title);
|
self.tab_model.text_set(tab, title);
|
||||||
return Task::batch([
|
return Task::batch([
|
||||||
self.update_title(),
|
self.update_title(),
|
||||||
self.update_watcher(),
|
self.update_watcher(),
|
||||||
self.rescan_tab(entity, location, None),
|
self.rescan_tab(tab, location, None),
|
||||||
if focus_search {
|
if focus_search {
|
||||||
widget::text_input::focus(self.search_id.clone())
|
widget::text_input::focus(self.search_id.clone())
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1767,7 +1771,7 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
if self.search_get().is_some() {
|
if self.search_get().is_some() {
|
||||||
// Close search if open
|
// Close search if open
|
||||||
return self.search_set(None);
|
return self.search_set_active(None);
|
||||||
}
|
}
|
||||||
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
|
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
|
||||||
if tab.context_menu.is_some() {
|
if tab.context_menu.is_some() {
|
||||||
|
|
@ -2298,8 +2302,12 @@ impl Application for App {
|
||||||
|
|
||||||
let mut commands = Vec::with_capacity(needs_reload.len());
|
let mut commands = Vec::with_capacity(needs_reload.len());
|
||||||
for (entity, location) in needs_reload {
|
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.rescan_tab(entity, location, None));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return Task::batch(commands);
|
return Task::batch(commands);
|
||||||
}
|
}
|
||||||
Message::NotifyWatcher(mut watcher_wrapper) => match watcher_wrapper.watcher_opt.take()
|
Message::NotifyWatcher(mut watcher_wrapper) => match watcher_wrapper.watcher_opt.take()
|
||||||
|
|
@ -2719,16 +2727,16 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
Message::SearchActivate => {
|
Message::SearchActivate => {
|
||||||
return if self.search_get().is_none() {
|
return if self.search_get().is_none() {
|
||||||
self.search_set(Some(String::new()))
|
self.search_set_active(Some(String::new()))
|
||||||
} else {
|
} else {
|
||||||
widget::text_input::focus(self.search_id.clone())
|
widget::text_input::focus(self.search_id.clone())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Message::SearchClear => {
|
Message::SearchClear => {
|
||||||
return self.search_set(None);
|
return self.search_set_active(None);
|
||||||
}
|
}
|
||||||
Message::SearchInput(input) => {
|
Message::SearchInput(input) => {
|
||||||
return self.search_set(Some(input));
|
return self.search_set_active(Some(input));
|
||||||
}
|
}
|
||||||
Message::SetShowDetails(show_details) => {
|
Message::SetShowDetails(show_details) => {
|
||||||
config_set!(show_details, show_details);
|
config_set!(show_details, show_details);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue