mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-30 13:04:13 +00:00
include current tags cleanup, enshort var names
This commit is contained in:
parent
b34cf7b34d
commit
a445c4c6a2
@ -10,7 +10,7 @@ use tag::Tag;
|
|||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
prelude::{BoxExt, ButtonExt, CheckButtonExt, EditableExt, TextBufferExt},
|
prelude::{BoxExt, ButtonExt, CheckButtonExt, EditableExt, TextBufferExt},
|
||||||
Align, Box, Button, Orientation, TextBuffer, TextIter, TextSearchFlags, TextTag,
|
Align, Box, Button, Orientation, TextBuffer, TextIter, TextSearchFlags,
|
||||||
};
|
};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
@ -23,13 +23,13 @@ pub struct Search {
|
|||||||
|
|
||||||
impl Search {
|
impl Search {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(text_buffer: &TextBuffer) -> Self {
|
pub fn new(buffer: &TextBuffer) -> Self {
|
||||||
// Init components
|
// Init components
|
||||||
let close = close::new();
|
let close = close::new();
|
||||||
let input = Rc::new(Input::new());
|
let input = Rc::new(Input::new());
|
||||||
let match_case = match_case::new();
|
let match_case = match_case::new();
|
||||||
let tag = Rc::new(Tag::new(text_buffer.tag_table()));
|
let tag = Rc::new(Tag::new(buffer.tag_table()));
|
||||||
let navigation = Rc::new(Navigation::new(text_buffer.clone(), tag.current.clone()));
|
let navigation = Rc::new(Navigation::new(buffer.clone(), tag.current.clone()));
|
||||||
|
|
||||||
// Init main container
|
// Init main container
|
||||||
let g_box = Box::builder()
|
let g_box = Box::builder()
|
||||||
@ -55,11 +55,11 @@ impl Search {
|
|||||||
let match_case = match_case.clone();
|
let match_case = match_case.clone();
|
||||||
let navigation = navigation.clone();
|
let navigation = navigation.clone();
|
||||||
let tag = tag.clone();
|
let tag = tag.clone();
|
||||||
let text_buffer = text_buffer.clone();
|
let buffer = buffer.clone();
|
||||||
move |_| {
|
move |_| {
|
||||||
navigation.update(find(
|
navigation.update(find(
|
||||||
&text_buffer,
|
&buffer,
|
||||||
&tag.found,
|
&tag,
|
||||||
input.entry.text().as_str(),
|
input.entry.text().as_str(),
|
||||||
match_case.is_active(),
|
match_case.is_active(),
|
||||||
));
|
));
|
||||||
@ -71,11 +71,11 @@ impl Search {
|
|||||||
let input = input.clone();
|
let input = input.clone();
|
||||||
let navigation = navigation.clone();
|
let navigation = navigation.clone();
|
||||||
let tag = tag.clone();
|
let tag = tag.clone();
|
||||||
let text_buffer = text_buffer.clone();
|
let buffer = buffer.clone();
|
||||||
move |this| {
|
move |this| {
|
||||||
navigation.update(find(
|
navigation.update(find(
|
||||||
&text_buffer,
|
&buffer,
|
||||||
&tag.found,
|
&tag,
|
||||||
input.entry.text().as_str(),
|
input.entry.text().as_str(),
|
||||||
this.is_active(),
|
this.is_active(),
|
||||||
));
|
));
|
||||||
@ -96,23 +96,20 @@ impl Search {
|
|||||||
// Tools
|
// Tools
|
||||||
|
|
||||||
fn find(
|
fn find(
|
||||||
text_buffer: &TextBuffer,
|
buffer: &TextBuffer,
|
||||||
found_tag: &TextTag,
|
tag: &Rc<Tag>,
|
||||||
subject: &str,
|
subject: &str,
|
||||||
is_match_case: bool,
|
is_match_case: bool,
|
||||||
) -> Vec<(TextIter, TextIter)> {
|
) -> Vec<(TextIter, TextIter)> {
|
||||||
// Init start matches result
|
// Init matches holder
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
|
|
||||||
// Cleanup previous search results
|
// Cleanup previous search highlights
|
||||||
text_buffer.remove_tag(
|
buffer.remove_tag(&tag.current, &buffer.start_iter(), &buffer.end_iter());
|
||||||
found_tag,
|
buffer.remove_tag(&tag.found, &buffer.start_iter(), &buffer.end_iter());
|
||||||
&text_buffer.start_iter(),
|
|
||||||
&text_buffer.end_iter(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Begin search
|
// Begin new search
|
||||||
let mut next = text_buffer.start_iter();
|
let mut next = buffer.start_iter();
|
||||||
while let Some((start, end)) = next.forward_search(
|
while let Some((start, end)) = next.forward_search(
|
||||||
subject,
|
subject,
|
||||||
match is_match_case {
|
match is_match_case {
|
||||||
@ -121,7 +118,7 @@ fn find(
|
|||||||
},
|
},
|
||||||
None, // unlimited
|
None, // unlimited
|
||||||
) {
|
) {
|
||||||
text_buffer.apply_tag(found_tag, &start, &end);
|
buffer.apply_tag(&tag.found, &start, &end);
|
||||||
next = end;
|
next = end;
|
||||||
result.push((start, end));
|
result.push((start, end));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user