WIP: Start converting SelectionSet to use AnchorRangeMap
This commit is contained in:
parent
3ae5ba09fd
commit
6ba4af3e26
5 changed files with 97 additions and 67 deletions
|
@ -2,7 +2,11 @@ use crate::Point;
|
|||
|
||||
use super::{Buffer, Content};
|
||||
use anyhow::Result;
|
||||
use std::{cmp::Ordering, ops::Range};
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
fmt::{Debug, Formatter},
|
||||
ops::Range,
|
||||
};
|
||||
use sum_tree::Bias;
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Debug, Hash)]
|
||||
|
@ -108,6 +112,14 @@ impl AnchorSet {
|
|||
}
|
||||
|
||||
impl<T> AnchorRangeMap<T> {
|
||||
pub fn from_raw(version: clock::Global, entries: Vec<(Range<(usize, Bias)>, T)>) -> Self {
|
||||
Self { version, entries }
|
||||
}
|
||||
|
||||
pub fn raw_entries(&self) -> &[(Range<(usize, Bias)>, T)] {
|
||||
&self.entries
|
||||
}
|
||||
|
||||
pub fn to_point_ranges<'a>(
|
||||
&'a self,
|
||||
content: impl Into<Content<'a>> + 'a,
|
||||
|
@ -123,6 +135,25 @@ impl<T> AnchorRangeMap<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: PartialEq> PartialEq for AnchorRangeMap<T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.version == other.version && self.entries == other.entries
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Eq> Eq for AnchorRangeMap<T> {}
|
||||
|
||||
impl<T: Debug> Debug for AnchorRangeMap<T> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
let f = f.debug_map();
|
||||
for (range, value) in &self.entries {
|
||||
f.key(range);
|
||||
f.value(value);
|
||||
}
|
||||
f.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl AnchorRangeSet {
|
||||
pub fn to_point_ranges<'a>(
|
||||
&'a self,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue