update results on match case toggle

This commit is contained in:
yggverse 2024-12-18 08:43:45 +02:00
parent 971ee50dfe
commit b1bf9e76ad
2 changed files with 14 additions and 9 deletions

View File

@ -63,11 +63,12 @@ impl Form {
input.entry.text().as_str(), input.entry.text().as_str(),
match_case.is_active(), match_case.is_active(),
); );
if !this.text().is_empty() && !matches.is_empty() { if !this.text().is_empty() {
result.show(0, matches.len()); result.update(0, matches.len());
result.label.set_visible(true);
separator.set_visible(true); separator.set_visible(true);
} else { } else {
result.hide(); result.label.set_visible(false);
separator.set_visible(false); separator.set_visible(false);
} }
input.update(!matches.is_empty()); input.update(!matches.is_empty());
@ -92,12 +93,21 @@ impl Form {
let input = input.clone(); let input = input.clone();
let navigation = navigation.clone(); let navigation = navigation.clone();
let subject = subject.clone(); let subject = subject.clone();
let input = input.clone();
move |this| { move |this| {
let matches = find( let matches = find(
subject.borrow().as_ref().unwrap(), // @TODO handle subject.borrow().as_ref().unwrap(), // @TODO handle
input.entry.text().as_str(), input.entry.text().as_str(),
this.is_active(), this.is_active(),
); );
if !input.entry.text().is_empty() {
result.update(0, matches.len());
result.label.set_visible(true);
separator.set_visible(true);
} else {
result.label.set_visible(false);
separator.set_visible(false);
}
input.update(!matches.is_empty()); input.update(!matches.is_empty());
navigation.update(matches); navigation.update(matches);
} }

View File

@ -22,7 +22,7 @@ impl Result {
// Actions // Actions
pub fn show(&self, current: usize, total: usize) { pub fn update(&self, current: usize, total: usize) {
if total > 0 { if total > 0 {
self.label self.label
.set_label(&format!("{current} if {total} matches")); .set_label(&format!("{current} if {total} matches"));
@ -31,10 +31,5 @@ impl Result {
self.label.set_label(&format!("Phrase not found")); self.label.set_label(&format!("Phrase not found"));
self.label.add_css_class("error"); self.label.add_css_class("error");
} }
self.label.set_visible(true);
}
pub fn hide(&self) {
self.label.set_visible(false);
} }
} }