pub struct BufferTracker { /* private fields */ }Implementations§
Source§impl BufferTracker
impl BufferTracker
Sourcepub fn request_parse(&self)
pub fn request_parse(&self)
Request for the Buffer to call Parser::parse
This will prompt the Buffer to be updated and only update
relevant Ranges, i.e., those that actually show up on
area and that have been added by to the BufferTracker via
add_range.
Sourcepub fn add_range(&mut self, range: impl TextRange)
pub fn add_range(&mut self, range: impl TextRange)
Adds a byte/Point Range to be updated on
Parser::update
This Range will be merged with other Ranges on the
list, and when a parse is requested, the intersections
between the Ranges sent to this method and the Range
of the Text shown on area will be updated.
For example, if you add the ranges 3..20 and 50..87, and
the range shown on area is 17..61, then two calls to
Parser::update will be made, one with the range
17..20 and one with the range 50..61. After that, the
ranges 3..17 and 61..87 will remain on the list of
Ranges to be updated
Sourcepub fn add_ranges<R: TextRange>(
&mut self,
new_ranges: impl IntoIterator<Item = R>,
)
pub fn add_ranges<R: TextRange>( &mut self, new_ranges: impl IntoIterator<Item = R>, )
Sourcepub fn track_changed_ranges(&mut self)
pub fn track_changed_ranges(&mut self)
Sourcepub fn track_changed_lines(&mut self)
pub fn track_changed_lines(&mut self)
Automatically add every changed line to the ranges to update
This function turns on automatic Range addition for every
line that a Change’s added range belongs to. You can
still add Ranges manually through add_range.
It’s probably the most common type of automatic range tracking that you’d want, since, for example, regex patterns are very convenient to separate line-wise, since most of them don’t tend to go over lines.
Additionally, this option will also make it so only whole
lines are updated. For example, if a line is partially cutoff
from the area, the range passed to Parser::update will
include the parts of the line that are outside of the area.
For the other tracking options, this won’t be the case.
Sourcepub fn track_area(&mut self)
pub fn track_area(&mut self)
Always update the whole area
This function basically turns off Range tracking and
assumes that you want to update the whole printed area.
One very common usecase of this is to do with parsing the
Selections. You may want to, for example, do something for
every selection that is visible on screen, maybe something
like this:
use duat::prelude::*;
// When construction the SelectionLen, I turned on area tracking
struct SelectionLen {
_tracker: BufferTracker,
tagger: Tagger,
}
impl Parser for SelectionLen {
fn update(&mut self, pa: &mut Pass, buffer: &Handle, on: Vec<Range<Point>>) {
let mut parts = buffer.text_mut(pa).parts();
// This is efficient even in very large `Text`s.
parts.tags.remove(self.tagger, ..);
for range in on {
for (_, selection, is_main) in parts.selections.iter_within(range) {
let range = selection.byte_range(&parts.bytes);
let (start, end) = (range.start, range.end);
let len = end - start;
if len > 2 {
let nums = len.ilog10() as usize + 1;
let ghost = Ghost(if is_main {
txt!("[sel_len.main]{len}")
} else {
txt!("[sel_len]{len}")
});
parts.tags.insert(self.tagger, start, ghost);
parts.tags.insert(self.tagger, start..start + nums, Conceal);
}
}
}
}
}This function will make it so, for every visible
Selection, its length in bytes will be displayed within
that selection with the "sel_len" Form.
§Note
This function is actually incorrect. It doesn’t take into account the possibility of intercepting newlines or the number being outside the printed area. The corrected version would be much too long for a simple example.
Sourcepub fn turn_off_tracking(&mut self)
pub fn turn_off_tracking(&mut self)
Sourcepub fn indent(&self, p: Point) -> usize
pub fn indent(&self, p: Point) -> usize
The indentation in the line at a Point
This value only takes ascii spaces and tabs into account,
which may differ from the value from Text::indent,
since that one calculates the indent through the Area,
while this one only makes use of the Buffer’s
PrintOpts.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BufferTracker
impl !RefUnwindSafe for BufferTracker
impl Send for BufferTracker
impl Sync for BufferTracker
impl Unpin for BufferTracker
impl !UnwindSafe for BufferTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.