mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 01:00:02 +00:00
use shared scroll_to_iter
method, fix scroll to iter on entry activate
This commit is contained in:
parent
c4fdad41eb
commit
7e70bfd87a
@ -11,7 +11,7 @@ use gtk::{
|
||||
BoxExt, ButtonExt, CheckButtonExt, EditableExt, EntryExt, TextBufferExt, TextViewExt,
|
||||
WidgetExt,
|
||||
},
|
||||
Align, Box, Orientation, TextIter, TextSearchFlags,
|
||||
Align, Box, Orientation, TextIter, TextSearchFlags, TextView,
|
||||
};
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
@ -60,27 +60,16 @@ impl Form {
|
||||
});
|
||||
|
||||
input.entry.connect_activate({
|
||||
let input = input.clone();
|
||||
let match_case = match_case.clone();
|
||||
let navigation = navigation.clone();
|
||||
let subject = subject.clone();
|
||||
move |_| {
|
||||
// try continue
|
||||
if navigation
|
||||
.forward(subject.borrow().as_ref().unwrap()) // @TODO handle
|
||||
.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
|
||||
move |_| match subject.borrow().as_ref() {
|
||||
Some(subject) => {
|
||||
if let Some((mut start, _)) = navigation.forward(subject) {
|
||||
scroll_to_iter(&subject.text_view, &mut start)
|
||||
}
|
||||
}
|
||||
None => todo!(),
|
||||
}
|
||||
});
|
||||
|
||||
match_case.connect_toggled({
|
||||
@ -103,11 +92,7 @@ impl Form {
|
||||
let navigation = navigation.clone();
|
||||
move |_| match subject.borrow().as_ref() {
|
||||
Some(subject) => match navigation.back(subject) {
|
||||
Some((mut start, _)) => {
|
||||
subject
|
||||
.text_view
|
||||
.scroll_to_iter(&mut start, 0.0, true, 0.0, 0.0);
|
||||
}
|
||||
Some((mut start, _)) => scroll_to_iter(&subject.text_view, &mut start),
|
||||
None => todo!(),
|
||||
},
|
||||
None => todo!(),
|
||||
@ -119,11 +104,7 @@ impl Form {
|
||||
let navigation = navigation.clone();
|
||||
move |_| match subject.borrow().as_ref() {
|
||||
Some(subject) => match navigation.forward(subject) {
|
||||
Some((mut start, _)) => {
|
||||
subject
|
||||
.text_view
|
||||
.scroll_to_iter(&mut start, 0.0, true, 0.0, 0.0);
|
||||
}
|
||||
Some((mut start, _)) => scroll_to_iter(&subject.text_view, &mut start),
|
||||
None => todo!(),
|
||||
},
|
||||
None => todo!(),
|
||||
@ -188,3 +169,7 @@ fn find(subject: &Subject, request: &str, is_match_case: bool) -> Vec<(TextIter,
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn scroll_to_iter(text_view: &TextView, iter: &mut TextIter) {
|
||||
text_view.scroll_to_iter(iter, 0.0, true, 0.0, 0.0);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user