pub struct RangesToUpdate<'b> { /* private fields */ }Expand description
A list of Range<usize>s of byte indices in a Buffer that
need to be updated
The recommended way to use this struct is the following:
- Firstly, this should all probably happen in the
BufferUpdatedhook, which is called right before printing to the screen. - Before calling
BufferTracker::parts, you should retrieve the ranges that you care about updating, either throughHandle::full_printed_rangeorHandle::printed_line_ranges. This is to update only what is visible, conserving cpu resources. - Then, with the received ranges, you can call
RangesToUpdate::cutoff,intersecting, orselect_from, in order to filter out which ranges need to be updated. - If updating the ranges was successfull, you can call
RangesToUpdate::update_onorupdate_intersecting, in order to declare those ranges as updated.
Implementations§
Source§impl<'b> RangesToUpdate<'b>
impl<'b> RangesToUpdate<'b>
Sourcepub fn add_ranges(
&self,
to_add: impl IntoIterator<Item = impl TextRange>,
) -> bool
pub fn add_ranges( &self, to_add: impl IntoIterator<Item = impl TextRange>, ) -> bool
Adds ranges to the list of those that need updating
Later on, when duat prints on a range that intersects with
these, you can call Handle::full_printed_range or
Handle::printed_line_ranges in order to get visible
ranges, and then call RangesToUpdate::cutoff, or
intersecting, or select_from, in order to get the
ranges that need updating, which will include these ones that
were added by this method, as well as those relating to the
changes that took place in the Buffer.
Returns true if any range was added at all.
Sourcepub fn update_on(
&self,
visible: impl IntoIterator<Item = impl TextRange>,
) -> bool
pub fn update_on( &self, visible: impl IntoIterator<Item = impl TextRange>, ) -> bool
Declares that the ranges given by the iterator have been updated
The visible iterator here should come from one of the methods
on the Handle<Buffer> which returns some list of visible
ranges. These include Handle::full_printed_range or
Handle::printed_line_ranges. You can, of course, also
feed only part of these lists, or some other arbitrary
range, in order to declare those updated too.
This function will then assume that you have successfully updated the ranges and will cut these out of the list. This will remove the intersections between the ranges that need to be updated and those of the iterator.
It will not completely remove ranges that partially
intersect those of the iterator, only truncating them. If you
want that behavior, see update_intersecting
Sourcepub fn update_intersecting(
&self,
visible: impl IntoIterator<Item = impl TextRange>,
) -> bool
pub fn update_intersecting( &self, visible: impl IntoIterator<Item = impl TextRange>, ) -> bool
Declares that any range intersecting with any of those on the iterator has been updated
The visible iterator here should come from one of the methods
on the Handle<Buffer> which returns some list of visible
ranges. These include Handle::full_printed_range or
Handle::printed_line_ranges. You can, of course, also
feed only part of these lists, or some other arbitrary
range, in order to declare those updated too.
If you want a method that only removes the intersection with
the ranges that need updating, see update_on.
Sourcepub fn cutoff(
&self,
visible: impl IntoIterator<Item = impl TextRange>,
) -> Vec<Range<usize>>
pub fn cutoff( &self, visible: impl IntoIterator<Item = impl TextRange>, ) -> Vec<Range<usize>>
Returns a list of intersections between the ranges that need updating and those from an iterator
The visible iterator here should come from one of the methods
on the Handle<Buffer> which returns some list of visible
ranges. These include Handle::full_printed_range or
Handle::printed_line_ranges. You can, of course, also
feed only part of these lists, or some other arbitrary
range, in order to declare those updated too.
Note that this returns only the intersecting bits. If you want
a list of all ranges that at least partially intersect, see
intersecting. If you want to do the opposite, i.e., select
all ranges from the iterator that intersect with those from
the list, see select_from.
This method is useful if you don’t need update full lines,
since it will only care about the ranges that have actually
changed, which aren’t full lines most of the time.
select_from is more useful for updating full lines, since
you can generate a list of printed lines from
Handle::printed_line_ranges, and select from those
only the ranges that have had changes in them. This pattern is
used, for example, by duat-treesitter.
Sourcepub fn intersecting(
&self,
visible: impl IntoIterator<Item = impl TextRange>,
) -> Vec<Range<usize>>
pub fn intersecting( &self, visible: impl IntoIterator<Item = impl TextRange>, ) -> Vec<Range<usize>>
Returns a list of all ranges that intersect with those from an iterator
The visible iterator here should come from one of the methods
on the Handle<Buffer> which returns some list of visible
ranges. These include Handle::full_printed_range or
Handle::printed_line_ranges. You can, of course, also
feed only part of these lists, or some other arbitrary
range, in order to declare those updated too.
Note that this returns the full ranges, not just the parts
that intersect. If you want a list of only the
intersections, see cutoff. If you want to select the
ranges in the iterator that intersect with those from the
list, see select_from.
Sourcepub fn select_from(
&self,
visible: impl IntoIterator<Item = impl TextRange>,
) -> Vec<Range<usize>>
pub fn select_from( &self, visible: impl IntoIterator<Item = impl TextRange>, ) -> Vec<Range<usize>>
Filters an iterator to a list of ranges that intersect with those that need updating
The visible iterator here should come from one of the methods
on the Handle<Buffer> which returns some list of visible
ranges. These include Handle::full_printed_range or
Handle::printed_line_ranges. You can, of course, also
feed only part of these lists, or some other arbitrary
range, in order to declare those updated too.
This method is really useful if you want to update on full
lines, but only do so if the lines have actually changed. If
the lines have had changes, those will be in the
RangesToUpdate. This method will check if the range of a
line intersects with the ranges that need updating. If that is
the case, that line will be kept in the returned Vec.
If you want a method that returns only the ranges that have
actually changed, check out cutoff. If you want a method
that that returns any range from the list that intersects with
those of the iterator, check out intersecting.
Auto Trait Implementations§
impl<'b> Freeze for RangesToUpdate<'b>
impl<'b> !RefUnwindSafe for RangesToUpdate<'b>
impl<'b> Send for RangesToUpdate<'b>
impl<'b> Sync for RangesToUpdate<'b>
impl<'b> Unpin for RangesToUpdate<'b>
impl<'b> !UnwindSafe for RangesToUpdate<'b>
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.