Improve range-based selection queries to only resolve the requested selections
This commit is contained in:
parent
09a53a0c64
commit
d249618ee6
4 changed files with 59 additions and 39 deletions
|
@ -210,14 +210,14 @@ impl<T> AnchorRangeMap<T> {
|
|||
.zip(self.entries.iter().map(|e| &e.1))
|
||||
}
|
||||
|
||||
pub fn intersecting_ranges<'a, D, T>(
|
||||
pub fn intersecting_ranges<'a, D, I>(
|
||||
&'a self,
|
||||
range: Range<(T, Bias)>,
|
||||
range: Range<(I, Bias)>,
|
||||
content: impl Into<Content<'a>> + 'a,
|
||||
) -> impl Iterator<Item = (Range<D>, &'a T)> + 'a
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
T: ToOffset,
|
||||
I: ToOffset,
|
||||
{
|
||||
let content = content.into();
|
||||
let range = content.anchor_at(range.start.0, range.start.1)
|
||||
|
@ -229,10 +229,20 @@ impl<T> AnchorRangeMap<T> {
|
|||
version: self.version.clone(),
|
||||
};
|
||||
let start_ix = self.entries.binary_search_by(|probe| {
|
||||
probe_anchor.full_offset = probe.0.start;
|
||||
probe_anchor.full_offset = probe.0.end;
|
||||
probe_anchor.cmp(&range.start, &content).unwrap()
|
||||
});
|
||||
std::iter::empty()
|
||||
|
||||
match start_ix {
|
||||
Ok(start_ix) | Err(start_ix) => content
|
||||
.summaries_for_anchor_ranges(
|
||||
self.version.clone(),
|
||||
self.start_bias,
|
||||
self.end_bias,
|
||||
self.entries[start_ix..].iter().map(|e| &e.0),
|
||||
)
|
||||
.zip(self.entries.iter().map(|e| &e.1)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn full_offset_ranges(&self) -> impl Iterator<Item = &(Range<FullOffset>, T)> {
|
||||
|
|
|
@ -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>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue