use shared scroll_to_iter method, fix scroll to iter on entry activate

This commit is contained in:
yggverse 2024-12-18 06:33:34 +02:00
parent c4fdad41eb
commit 7e70bfd87a

View File

@ -11,7 +11,7 @@ use gtk::{
BoxExt, ButtonExt, CheckButtonExt, EditableExt, EntryExt, TextBufferExt, TextViewExt, BoxExt, ButtonExt, CheckButtonExt, EditableExt, EntryExt, TextBufferExt, TextViewExt,
WidgetExt, WidgetExt,
}, },
Align, Box, Orientation, TextIter, TextSearchFlags, Align, Box, Orientation, TextIter, TextSearchFlags, TextView,
}; };
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
@ -60,27 +60,16 @@ impl Form {
}); });
input.entry.connect_activate({ input.entry.connect_activate({
let input = input.clone();
let match_case = match_case.clone();
let navigation = navigation.clone(); let navigation = navigation.clone();
let subject = subject.clone(); let subject = subject.clone();
move |_| { move |_| match subject.borrow().as_ref() {
// try continue Some(subject) => {
if navigation if let Some((mut start, _)) = navigation.forward(subject) {
.forward(subject.borrow().as_ref().unwrap()) // @TODO handle scroll_to_iter(&subject.text_view, &mut start)
.is_none()
{
// begin new search
let matches = find(
subject.borrow().as_ref().unwrap(), // @TODO handle
input.entry.text().as_str(),
match_case.is_active(),
);
input.update(!matches.is_empty());
navigation.update(matches);
navigation.forward(subject.borrow().as_ref().unwrap()); // @TODO handle
} }
} }
None => todo!(),
}
}); });
match_case.connect_toggled({ match_case.connect_toggled({
@ -103,11 +92,7 @@ impl Form {
let navigation = navigation.clone(); let navigation = navigation.clone();
move |_| match subject.borrow().as_ref() { move |_| match subject.borrow().as_ref() {
Some(subject) => match navigation.back(subject) { Some(subject) => match navigation.back(subject) {
Some((mut start, _)) => { Some((mut start, _)) => scroll_to_iter(&subject.text_view, &mut start),
subject
.text_view
.scroll_to_iter(&mut start, 0.0, true, 0.0, 0.0);
}
None => todo!(), None => todo!(),
}, },
None => todo!(), None => todo!(),
@ -119,11 +104,7 @@ impl Form {
let navigation = navigation.clone(); let navigation = navigation.clone();
move |_| match subject.borrow().as_ref() { move |_| match subject.borrow().as_ref() {
Some(subject) => match navigation.forward(subject) { Some(subject) => match navigation.forward(subject) {
Some((mut start, _)) => { Some((mut start, _)) => scroll_to_iter(&subject.text_view, &mut start),
subject
.text_view
.scroll_to_iter(&mut start, 0.0, true, 0.0, 0.0);
}
None => todo!(), None => todo!(),
}, },
None => todo!(), None => todo!(),
@ -188,3 +169,7 @@ fn find(subject: &Subject, request: &str, is_match_case: bool) -> Vec<(TextIter,
} }
result result
} }
fn scroll_to_iter(text_view: &TextView, iter: &mut TextIter) {
text_view.scroll_to_iter(iter, 0.0, true, 0.0, 0.0);
}