mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-30 13:04:13 +00:00
prevent search on empty request, fix search results cleanup
This commit is contained in:
parent
61fd237b80
commit
e35b5e82e9
@ -58,18 +58,18 @@ impl Form {
|
|||||||
let separator = separator.clone();
|
let separator = separator.clone();
|
||||||
let subject = subject.clone();
|
let subject = subject.clone();
|
||||||
move |this| {
|
move |this| {
|
||||||
let matches = find(
|
navigation.renew(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(),
|
||||||
match_case.is_active(),
|
match_case.is_active(),
|
||||||
);
|
));
|
||||||
input.update(!matches.is_empty());
|
|
||||||
navigation.renew(matches);
|
|
||||||
if !this.text().is_empty() {
|
if !this.text().is_empty() {
|
||||||
result.update(navigation.position(), navigation.total());
|
input.update(navigation.total() > 0);
|
||||||
result.label.set_visible(true);
|
result.label.set_visible(true);
|
||||||
|
result.update(navigation.position(), navigation.total());
|
||||||
separator.set_visible(true);
|
separator.set_visible(true);
|
||||||
} else {
|
} else {
|
||||||
|
input.update(true);
|
||||||
result.label.set_visible(false);
|
result.label.set_visible(false);
|
||||||
separator.set_visible(false);
|
separator.set_visible(false);
|
||||||
}
|
}
|
||||||
@ -104,18 +104,18 @@ impl Form {
|
|||||||
let result = result.clone();
|
let result = result.clone();
|
||||||
let subject = subject.clone();
|
let subject = subject.clone();
|
||||||
move |this| {
|
move |this| {
|
||||||
let matches = find(
|
navigation.renew(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(),
|
||||||
);
|
));
|
||||||
input.update(!matches.is_empty());
|
|
||||||
navigation.renew(matches);
|
|
||||||
if !input.entry.text().is_empty() {
|
if !input.entry.text().is_empty() {
|
||||||
result.update(navigation.position(), navigation.total());
|
input.update(navigation.total() > 0);
|
||||||
result.label.set_visible(true);
|
result.label.set_visible(true);
|
||||||
|
result.update(navigation.position(), navigation.total());
|
||||||
separator.set_visible(true);
|
separator.set_visible(true);
|
||||||
} else {
|
} else {
|
||||||
|
input.update(true);
|
||||||
result.label.set_visible(false);
|
result.label.set_visible(false);
|
||||||
separator.set_visible(false);
|
separator.set_visible(false);
|
||||||
}
|
}
|
||||||
@ -181,9 +181,6 @@ impl Form {
|
|||||||
// Tools
|
// Tools
|
||||||
|
|
||||||
fn find(subject: &Subject, request: &str, is_match_case: bool) -> Vec<(TextIter, TextIter)> {
|
fn find(subject: &Subject, request: &str, is_match_case: bool) -> Vec<(TextIter, TextIter)> {
|
||||||
// Init matches holder
|
|
||||||
let mut result = Vec::new();
|
|
||||||
|
|
||||||
// Get iters
|
// Get iters
|
||||||
let (buffer_start, buffer_end) = subject.text_view.buffer().bounds();
|
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()
|
.buffer()
|
||||||
.remove_tag(&subject.tag.found, &buffer_start, &buffer_end);
|
.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
|
// Begin new search
|
||||||
let mut next = buffer_start;
|
let mut next = buffer_start;
|
||||||
while let Some((match_start, match_end)) = next.forward_search(
|
while let Some((match_start, match_end)) = next.forward_search(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user