Improve range-based selection queries to only resolve the requested selections

This commit is contained in:
Nathan Sobo 2021-11-25 13:19:49 -07:00
parent 09a53a0c64
commit d249618ee6
4 changed files with 59 additions and 39 deletions

View file

@ -1,3 +1,5 @@
use sum_tree::Bias;
use crate::rope::TextDimension;
use super::{AnchorRangeMap, Buffer, Content, Point, ToOffset, ToPoint};
@ -117,6 +119,27 @@ impl SelectionSet {
})
}
pub fn intersecting_selections<'a, D, I, C>(
&'a self,
range: Range<(I, Bias)>,
content: C,
) -> impl 'a + Iterator<Item = Selection<D>>
where
D: 'a + TextDimension<'a>,
I: 'a + ToOffset,
C: 'a + Into<Content<'a>>,
{
self.selections
.intersecting_ranges(range, content)
.map(|(range, state)| Selection {
id: state.id,
start: range.start,
end: range.end,
reversed: state.reversed,
goal: state.goal,
})
}
pub fn oldest_selection<'a, D, C>(&'a self, content: C) -> Option<Selection<D>>
where
D: 'a + TextDimension<'a>,