mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 01:00:02 +00:00
make back/forward result optional
This commit is contained in:
parent
b9bdaaa495
commit
d8a4e42f3c
@ -83,10 +83,14 @@ impl Form {
|
||||
move |this| match subject.borrow().as_ref() {
|
||||
Some(subject) => {
|
||||
if !this.text().is_empty() {
|
||||
let (mut start, _) = navigation.forward(subject);
|
||||
match navigation.forward(subject) {
|
||||
Some((mut start, _)) => {
|
||||
result.update(navigation.position(), navigation.total());
|
||||
scroll_to_iter(&subject.text_view, &mut start)
|
||||
}
|
||||
None => todo!(), // unexpected
|
||||
}
|
||||
}
|
||||
}
|
||||
None => todo!(),
|
||||
}
|
||||
@ -123,10 +127,14 @@ impl Form {
|
||||
let subject = subject.clone();
|
||||
move |_| match subject.borrow().as_ref() {
|
||||
Some(subject) => {
|
||||
let (mut start, _) = navigation.back(subject);
|
||||
match navigation.back(subject) {
|
||||
Some((mut start, _)) => {
|
||||
result.update(navigation.position(), navigation.total());
|
||||
scroll_to_iter(&subject.text_view, &mut start)
|
||||
}
|
||||
None => todo!(), // unexpected
|
||||
}
|
||||
}
|
||||
None => todo!(),
|
||||
}
|
||||
});
|
||||
@ -136,11 +144,13 @@ impl Form {
|
||||
let result = result.clone();
|
||||
let subject = subject.clone();
|
||||
move |_| match subject.borrow().as_ref() {
|
||||
Some(subject) => {
|
||||
let (mut start, _) = navigation.forward(subject);
|
||||
Some(subject) => match navigation.forward(subject) {
|
||||
Some((mut start, _)) => {
|
||||
result.update(navigation.position(), navigation.total());
|
||||
scroll_to_iter(&subject.text_view, &mut start)
|
||||
}
|
||||
None => todo!(), // unexpected
|
||||
},
|
||||
None => todo!(),
|
||||
}
|
||||
});
|
||||
|
@ -64,7 +64,7 @@ impl Navigation {
|
||||
/// * return `start`/`end` iters to scroll up the widget
|
||||
/// * user should not activate this function on empty results
|
||||
/// expected all actions / buttons deactivated in this case
|
||||
pub fn back(&self, subject: &Subject) -> (TextIter, TextIter) {
|
||||
pub fn back(&self, subject: &Subject) -> Option<(TextIter, TextIter)> {
|
||||
let buffer = subject.text_view.buffer();
|
||||
|
||||
buffer.remove_tag(
|
||||
@ -75,23 +75,22 @@ impl Navigation {
|
||||
|
||||
let mut model = self.model.borrow_mut();
|
||||
|
||||
let (start, end) = match model.back() {
|
||||
Some((start, end)) => (*start, *end),
|
||||
None => todo!(), // unexpected
|
||||
};
|
||||
|
||||
match model.back().map(|(start, end)| (*start, *end)) {
|
||||
Some((start, end)) => {
|
||||
if model.position().is_some() {
|
||||
buffer.apply_tag(&subject.tag.current, &start, &end);
|
||||
}
|
||||
|
||||
(start, end)
|
||||
Some((start, end))
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Navigate forward in matches, apply tags to buffer
|
||||
/// * return `start`/`end` iters to scroll down the widget
|
||||
/// * user should not activate this function on empty results
|
||||
/// expected all actions / buttons deactivated in this case
|
||||
pub fn forward(&self, subject: &Subject) -> (TextIter, TextIter) {
|
||||
pub fn forward(&self, subject: &Subject) -> Option<(TextIter, TextIter)> {
|
||||
let buffer = subject.text_view.buffer();
|
||||
|
||||
buffer.remove_tag(
|
||||
@ -102,16 +101,15 @@ impl Navigation {
|
||||
|
||||
let mut model = self.model.borrow_mut();
|
||||
|
||||
let (start, end) = match model.next() {
|
||||
Some((start, end)) => (*start, *end),
|
||||
None => todo!(), // unexpected
|
||||
};
|
||||
|
||||
match model.next().map(|(start, end)| (*start, *end)) {
|
||||
Some((start, end)) => {
|
||||
if model.position().is_some() {
|
||||
buffer.apply_tag(&subject.tag.current, &start, &end);
|
||||
}
|
||||
|
||||
(start, end)
|
||||
Some((start, end))
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
Loading…
x
Reference in New Issue
Block a user