mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
draft find method
This commit is contained in:
parent
1ce46c680b
commit
02df33428e
@ -24,8 +24,8 @@ use gtk::{
|
|||||||
gio::Cancellable,
|
gio::Cancellable,
|
||||||
glib::{TimeZone, Uri},
|
glib::{TimeZone, Uri},
|
||||||
prelude::{TextBufferExt, TextBufferExtManual, TextTagExt, TextViewExt, WidgetExt},
|
prelude::{TextBufferExt, TextBufferExtManual, TextTagExt, TextViewExt, WidgetExt},
|
||||||
EventControllerMotion, GestureClick, TextBuffer, TextTag, TextWindowType, UriLauncher, Window,
|
EventControllerMotion, GestureClick, TextBuffer, TextSearchFlags, TextTag, TextWindowType,
|
||||||
WrapMode,
|
UriLauncher, Window, WrapMode,
|
||||||
};
|
};
|
||||||
use std::{cell::Cell, collections::HashMap, rc::Rc};
|
use std::{cell::Cell, collections::HashMap, rc::Rc};
|
||||||
|
|
||||||
@ -39,6 +39,8 @@ const LINK_COLOR_DEFAULT: (f32, f32, f32, f32) = (53.0, 132.0, 228.0, 255.0);
|
|||||||
const LINK_COLOR_ONHOVER: (f32, f32, f32, f32) = (53.0, 132.0, 228.0, 228.0);
|
const LINK_COLOR_ONHOVER: (f32, f32, f32, f32) = (53.0, 132.0, 228.0, 228.0);
|
||||||
|
|
||||||
pub struct Reader {
|
pub struct Reader {
|
||||||
|
buffer: TextBuffer,
|
||||||
|
tag: Tag,
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
pub widget: Rc<Widget>,
|
pub widget: Rc<Widget>,
|
||||||
}
|
}
|
||||||
@ -303,7 +305,7 @@ impl Reader {
|
|||||||
|
|
||||||
// Nothing match custom tags above,
|
// Nothing match custom tags above,
|
||||||
// just append plain text covered in empty tag (to handle controller events properly)
|
// just append plain text covered in empty tag (to handle controller events properly)
|
||||||
let tag = TextTag::builder().wrap_mode(WrapMode::Word).build();
|
let tag = TextTag::builder().wrap_mode(WrapMode::Word).build(); // @TODO single shared
|
||||||
|
|
||||||
buffer.tag_table().add(&tag);
|
buffer.tag_table().add(&tag);
|
||||||
buffer.insert_with_tags(&mut buffer.end_iter(), line, &[&tag]);
|
buffer.insert_with_tags(&mut buffer.end_iter(), line, &[&tag]);
|
||||||
@ -459,7 +461,33 @@ impl Reader {
|
|||||||
}); // @TODO may be expensive for CPU, add timeout?
|
}); // @TODO may be expensive for CPU, add timeout?
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
Ok(Self { title, widget })
|
Ok(Self {
|
||||||
|
buffer,
|
||||||
|
tag,
|
||||||
|
title,
|
||||||
|
widget,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
|
||||||
|
pub fn find(&self) {
|
||||||
|
self.buffer.remove_tag(
|
||||||
|
&self.tag.found.text_tag,
|
||||||
|
&self.buffer.start_iter(),
|
||||||
|
&self.buffer.end_iter(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut next = self.buffer.start_iter();
|
||||||
|
while let Some((start, end)) = next.forward_search(
|
||||||
|
"Gemini",
|
||||||
|
TextSearchFlags::CASE_INSENSITIVE, // @TODO
|
||||||
|
None, // unlimited
|
||||||
|
) {
|
||||||
|
self.buffer
|
||||||
|
.apply_tag(&self.tag.found.text_tag, &start, &end);
|
||||||
|
next = end;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user