From e35b5e82e9990551b5364bd064157fa28b9c9428 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 18 Dec 2024 16:21:35 +0200 Subject: [PATCH] prevent search on empty request, fix search results cleanup --- .../window/tab/item/page/search/form.rs | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/app/browser/window/tab/item/page/search/form.rs b/src/app/browser/window/tab/item/page/search/form.rs index b9334628..690221bb 100644 --- a/src/app/browser/window/tab/item/page/search/form.rs +++ b/src/app/browser/window/tab/item/page/search/form.rs @@ -58,18 +58,18 @@ impl Form { let separator = separator.clone(); let subject = subject.clone(); move |this| { - let matches = find( + navigation.renew(find( subject.borrow().as_ref().unwrap(), // @TODO handle input.entry.text().as_str(), match_case.is_active(), - ); - input.update(!matches.is_empty()); - navigation.renew(matches); + )); if !this.text().is_empty() { - result.update(navigation.position(), navigation.total()); + input.update(navigation.total() > 0); result.label.set_visible(true); + result.update(navigation.position(), navigation.total()); separator.set_visible(true); } else { + input.update(true); result.label.set_visible(false); separator.set_visible(false); } @@ -104,18 +104,18 @@ impl Form { let result = result.clone(); let subject = subject.clone(); move |this| { - let matches = find( + navigation.renew(find( subject.borrow().as_ref().unwrap(), // @TODO handle input.entry.text().as_str(), this.is_active(), - ); - input.update(!matches.is_empty()); - navigation.renew(matches); + )); if !input.entry.text().is_empty() { - result.update(navigation.position(), navigation.total()); + input.update(navigation.total() > 0); result.label.set_visible(true); + result.update(navigation.position(), navigation.total()); separator.set_visible(true); } else { + input.update(true); result.label.set_visible(false); separator.set_visible(false); } @@ -181,9 +181,6 @@ impl Form { // Tools fn find(subject: &Subject, request: &str, is_match_case: bool) -> Vec<(TextIter, TextIter)> { - // Init matches holder - let mut result = Vec::new(); - // Get iters let (buffer_start, buffer_end) = subject.text_view.buffer().bounds(); @@ -197,6 +194,14 @@ fn find(subject: &Subject, request: &str, is_match_case: bool) -> Vec<(TextIter, .buffer() .remove_tag(&subject.tag.found, &buffer_start, &buffer_end); + // Init matches holder + let mut result = Vec::new(); + + // Skip search for empty request + if request.is_empty() { + return result; + } + // Begin new search let mut next = buffer_start; while let Some((match_start, match_end)) = next.forward_search(