Allow seeking SumTree cursor by multiple seek types per dimension

Also, remove the cursor's sum_dimension. Replace it with a
blanket implementation of Dimension for two-element tuples
of dimensions.

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld
2021-09-24 18:23:53 -07:00
co-authored by Nathan Sobo
parent 39fbf7d4d1
commit ab31ddfc31
11 changed files with 458 additions and 509 deletions
+8 -14
View File
@@ -68,7 +68,7 @@ pub struct ChannelMessageSummary {
count: usize,
}
#[derive(Copy, Clone, Debug, Default)]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
struct Count(usize);
pub enum ChannelListEvent {}
@@ -387,19 +387,19 @@ impl Channel {
}
pub fn message(&self, ix: usize) -> &ChannelMessage {
let mut cursor = self.messages.cursor::<Count, ()>();
let mut cursor = self.messages.cursor::<Count>();
cursor.seek(&Count(ix), Bias::Right, &());
cursor.item().unwrap()
}
pub fn messages_in_range(&self, range: Range<usize>) -> impl Iterator<Item = &ChannelMessage> {
let mut cursor = self.messages.cursor::<Count, ()>();
let mut cursor = self.messages.cursor::<Count>();
cursor.seek(&Count(range.start), Bias::Right, &());
cursor.take(range.len())
}
pub fn pending_messages(&self) -> impl Iterator<Item = &ChannelMessage> {
let mut cursor = self.messages.cursor::<ChannelMessageId, ()>();
let mut cursor = self.messages.cursor::<ChannelMessageId>();
cursor.seek(&ChannelMessageId::Pending(0), Bias::Left, &());
cursor
}
@@ -433,13 +433,13 @@ impl Channel {
fn insert_messages(&mut self, messages: SumTree<ChannelMessage>, cx: &mut ModelContext<Self>) {
if let Some((first_message, last_message)) = messages.first().zip(messages.last()) {
let nonces = messages
.cursor::<(), ()>()
.cursor::<()>()
.map(|m| m.nonce)
.collect::<HashSet<_>>();
let mut old_cursor = self.messages.cursor::<ChannelMessageId, Count>();
let mut old_cursor = self.messages.cursor::<(ChannelMessageId, Count)>();
let mut new_messages = old_cursor.slice(&first_message.id, Bias::Left, &());
let start_ix = old_cursor.sum_start().0;
let start_ix = old_cursor.start().1 .0;
let removed_messages = old_cursor.slice(&last_message.id, Bias::Right, &());
let removed_count = removed_messages.summary().count;
let new_count = messages.summary().count;
@@ -457,7 +457,7 @@ impl Channel {
);
while let Some(message) = old_cursor.item() {
let message_ix = old_cursor.sum_start().0;
let message_ix = old_cursor.start().1 .0;
if nonces.contains(&message.nonce) {
if ranges.last().map_or(false, |r| r.end == message_ix) {
ranges.last_mut().unwrap().end += 1;
@@ -591,12 +591,6 @@ impl<'a> sum_tree::Dimension<'a, ChannelMessageSummary> for Count {
}
}
impl<'a> sum_tree::SeekDimension<'a, ChannelMessageSummary> for Count {
fn cmp(&self, other: &Self, _: &()) -> std::cmp::Ordering {
Ord::cmp(&self.0, &other.0)
}
}
#[cfg(test)]
mod tests {
use super::*;
+33 -33
View File
@@ -1455,21 +1455,21 @@ impl Buffer {
let cx = Some(version.clone());
let mut new_ropes =
RopeBuilder::new(self.visible_text.cursor(0), self.deleted_text.cursor(0));
let mut old_fragments = self.fragments.cursor::<VersionedOffset, VersionedOffset>();
let mut old_fragments = self.fragments.cursor::<VersionedOffset>();
let mut new_fragments =
old_fragments.slice(&VersionedOffset::Offset(ranges[0].start), Bias::Left, &cx);
new_ropes.push_tree(new_fragments.summary().text);
let mut fragment_start = old_fragments.sum_start().offset();
let mut fragment_start = old_fragments.start().offset();
for range in ranges {
let fragment_end = old_fragments.sum_end(&cx).offset();
let fragment_end = old_fragments.end(&cx).offset();
// If the current fragment ends before this range, then jump ahead to the first fragment
// that extends past the start of this range, reusing any intervening fragments.
if fragment_end < range.start {
// If the current fragment has been partially consumed, then consume the rest of it
// and advance to the next fragment before slicing.
if fragment_start > old_fragments.sum_start().offset() {
if fragment_start > old_fragments.start().offset() {
if fragment_end > fragment_start {
let mut suffix = old_fragments.item().unwrap().clone();
suffix.len = fragment_end - fragment_start;
@@ -1483,18 +1483,18 @@ impl Buffer {
old_fragments.slice(&VersionedOffset::Offset(range.start), Bias::Left, &cx);
new_ropes.push_tree(slice.summary().text);
new_fragments.push_tree(slice, &None);
fragment_start = old_fragments.sum_start().offset();
fragment_start = old_fragments.start().offset();
}
// If we are at the end of a non-concurrent fragment, advance to the next one.
let fragment_end = old_fragments.sum_end(&cx).offset();
let fragment_end = old_fragments.end(&cx).offset();
if fragment_end == range.start && fragment_end > fragment_start {
let mut fragment = old_fragments.item().unwrap().clone();
fragment.len = fragment_end - fragment_start;
new_ropes.push_fragment(&fragment, fragment.visible);
new_fragments.push(fragment, &None);
old_fragments.next(&cx);
fragment_start = old_fragments.sum_start().offset();
fragment_start = old_fragments.start().offset();
}
// Skip over insertions that are concurrent to this edit, but have a lower lamport
@@ -1541,7 +1541,7 @@ impl Buffer {
// portions as deleted.
while fragment_start < range.end {
let fragment = old_fragments.item().unwrap();
let fragment_end = old_fragments.sum_end(&cx).offset();
let fragment_end = old_fragments.end(&cx).offset();
let mut intersection = fragment.clone();
let intersection_end = cmp::min(range.end, fragment_end);
if fragment.was_visible(version, &self.undo_map) {
@@ -1562,8 +1562,8 @@ impl Buffer {
// If the current fragment has been partially consumed, then consume the rest of it
// and advance to the next fragment before slicing.
if fragment_start > old_fragments.sum_start().offset() {
let fragment_end = old_fragments.sum_end(&cx).offset();
if fragment_start > old_fragments.start().offset() {
let fragment_end = old_fragments.end(&cx).offset();
if fragment_end > fragment_start {
let mut suffix = old_fragments.item().unwrap().clone();
suffix.len = fragment_end - fragment_start;
@@ -1679,7 +1679,7 @@ impl Buffer {
}
let cx = Some(cx);
let mut old_fragments = self.fragments.cursor::<VersionedOffset, VersionedOffset>();
let mut old_fragments = self.fragments.cursor::<VersionedOffset>();
let mut new_fragments = old_fragments.slice(
&VersionedOffset::Offset(undo.ranges[0].start),
Bias::Right,
@@ -1690,7 +1690,7 @@ impl Buffer {
new_ropes.push_tree(new_fragments.summary().text);
for range in &undo.ranges {
let mut end_offset = old_fragments.sum_end(&cx).offset();
let mut end_offset = old_fragments.end(&cx).offset();
if end_offset < range.start {
let preceding_fragments =
@@ -1714,7 +1714,7 @@ impl Buffer {
new_fragments.push(fragment, &None);
old_fragments.next(&cx);
if end_offset == old_fragments.sum_end(&cx).offset() {
if end_offset == old_fragments.end(&cx).offset() {
let unseen_fragments = old_fragments.slice(
&VersionedOffset::Offset(end_offset),
Bias::Right,
@@ -1723,7 +1723,7 @@ impl Buffer {
new_ropes.push_tree(unseen_fragments.summary().text);
new_fragments.push_tree(unseen_fragments, &None);
}
end_offset = old_fragments.sum_end(&cx).offset();
end_offset = old_fragments.end(&cx).offset();
} else {
break;
}
@@ -1799,20 +1799,20 @@ impl Buffer {
let mut new_ropes =
RopeBuilder::new(self.visible_text.cursor(0), self.deleted_text.cursor(0));
let mut old_fragments = self.fragments.cursor::<usize, FragmentTextSummary>();
let mut old_fragments = self.fragments.cursor::<(usize, FragmentTextSummary)>();
let mut new_fragments = old_fragments.slice(&ranges[0].start, Bias::Right, &None);
new_ropes.push_tree(new_fragments.summary().text);
let mut fragment_start = old_fragments.sum_start().visible;
let mut fragment_start = old_fragments.start().1.visible;
for range in ranges {
let fragment_end = old_fragments.sum_end(&None).visible;
let fragment_end = old_fragments.end(&None).1.visible;
// If the current fragment ends before this range, then jump ahead to the first fragment
// that extends past the start of this range, reusing any intervening fragments.
if fragment_end < range.start {
// If the current fragment has been partially consumed, then consume the rest of it
// and advance to the next fragment before slicing.
if fragment_start > old_fragments.sum_start().visible {
if fragment_start > old_fragments.start().1.visible {
if fragment_end > fragment_start {
let mut suffix = old_fragments.item().unwrap().clone();
suffix.len = fragment_end - fragment_start;
@@ -1825,10 +1825,10 @@ impl Buffer {
let slice = old_fragments.slice(&range.start, Bias::Right, &None);
new_ropes.push_tree(slice.summary().text);
new_fragments.push_tree(slice, &None);
fragment_start = old_fragments.sum_start().visible;
fragment_start = old_fragments.start().1.visible;
}
let full_range_start = range.start + old_fragments.sum_start().deleted;
let full_range_start = range.start + old_fragments.start().1.deleted;
// Preserve any portion of the current fragment that precedes this range.
if fragment_start < range.start {
@@ -1858,7 +1858,7 @@ impl Buffer {
// portions as deleted.
while fragment_start < range.end {
let fragment = old_fragments.item().unwrap();
let fragment_end = old_fragments.sum_end(&None).visible;
let fragment_end = old_fragments.end(&None).1.visible;
let mut intersection = fragment.clone();
let intersection_end = cmp::min(range.end, fragment_end);
if fragment.visible {
@@ -1876,14 +1876,14 @@ impl Buffer {
}
}
let full_range_end = range.end + old_fragments.sum_start().deleted;
let full_range_end = range.end + old_fragments.start().1.deleted;
edit.ranges.push(full_range_start..full_range_end);
}
// If the current fragment has been partially consumed, then consume the rest of it
// and advance to the next fragment before slicing.
if fragment_start > old_fragments.sum_start().visible {
let fragment_end = old_fragments.sum_end(&None).visible;
if fragment_start > old_fragments.start().1.visible {
let fragment_end = old_fragments.end(&None).1.visible;
if fragment_end > fragment_start {
let mut suffix = old_fragments.item().unwrap().clone();
suffix.len = fragment_end - fragment_start;
@@ -2156,14 +2156,14 @@ impl<'a> Content<'a> {
fn summary_for_anchor(&self, anchor: &Anchor) -> TextSummary {
let cx = Some(anchor.version.clone());
let mut cursor = self.fragments.cursor::<VersionedOffset, usize>();
let mut cursor = self.fragments.cursor::<(VersionedOffset, usize)>();
cursor.seek(&VersionedOffset::Offset(anchor.offset), anchor.bias, &cx);
let overshoot = if cursor.item().map_or(false, |fragment| fragment.visible) {
anchor.offset - cursor.seek_start().offset()
anchor.offset - cursor.start().0.offset()
} else {
0
};
self.text_summary_for_range(0..*cursor.sum_start() + overshoot)
self.text_summary_for_range(0..cursor.start().1 + overshoot)
}
fn text_summary_for_range(&self, range: Range<usize>) -> TextSummary {
@@ -2174,10 +2174,10 @@ impl<'a> Content<'a> {
let offset = position.to_offset(self);
let max_offset = self.len();
assert!(offset <= max_offset, "offset is out of range");
let mut cursor = self.fragments.cursor::<usize, FragmentTextSummary>();
let mut cursor = self.fragments.cursor::<(usize, FragmentTextSummary)>();
cursor.seek(&offset, bias, &None);
Anchor {
offset: offset + cursor.sum_start().deleted,
offset: offset + cursor.start().1.deleted,
bias,
version: self.version.clone(),
}
@@ -2187,14 +2187,14 @@ impl<'a> Content<'a> {
let cx = Some(anchor.version.clone());
let mut cursor = self
.fragments
.cursor::<VersionedOffset, FragmentTextSummary>();
.cursor::<(VersionedOffset, FragmentTextSummary)>();
cursor.seek(&VersionedOffset::Offset(anchor.offset), anchor.bias, &cx);
let overshoot = if cursor.item().is_some() {
anchor.offset - cursor.seek_start().offset()
anchor.offset - cursor.start().0.offset()
} else {
0
};
let summary = cursor.sum_start();
let summary = cursor.start().1;
summary.visible + summary.deleted + overshoot
}
@@ -2589,7 +2589,7 @@ impl<'a> sum_tree::Dimension<'a, FragmentSummary> for VersionedOffset {
}
}
impl<'a> sum_tree::SeekDimension<'a, FragmentSummary> for VersionedOffset {
impl<'a> sum_tree::SeekTarget<'a, FragmentSummary, Self> for VersionedOffset {
fn cmp(&self, other: &Self, _: &Option<time::Global>) -> cmp::Ordering {
match (self, other) {
(Self::Offset(a), Self::Offset(b)) => Ord::cmp(a, b),
+1 -1
View File
@@ -43,7 +43,7 @@ impl OperationQueue {
clone
}
pub fn cursor(&self) -> Cursor<Operation, (), ()> {
pub fn cursor(&self) -> Cursor<Operation, ()> {
self.0.cursor()
}
}
+29 -35
View File
@@ -22,7 +22,7 @@ impl Rope {
}
pub fn append(&mut self, rope: Rope) {
let mut chunks = rope.chunks.cursor::<(), ()>();
let mut chunks = rope.chunks.cursor::<()>();
chunks.next(&());
if let Some(chunk) = chunks.item() {
if self.chunks.last().map_or(false, |c| c.0.len() < CHUNK_BASE)
@@ -83,7 +83,7 @@ impl Rope {
{
// Ensure all chunks except maybe the last one are not underflowing.
// Allow some wiggle room for multibyte characters at chunk boundaries.
let mut chunks = self.chunks.cursor::<(), ()>().peekable();
let mut chunks = self.chunks.cursor::<()>().peekable();
while let Some(chunk) = chunks.next() {
if chunks.peek().is_some() {
assert!(chunk.0.len() + 3 >= CHUNK_BASE);
@@ -126,10 +126,10 @@ impl Rope {
pub fn to_point(&self, offset: usize) -> Point {
assert!(offset <= self.summary().bytes);
let mut cursor = self.chunks.cursor::<usize, Point>();
let mut cursor = self.chunks.cursor::<(usize, Point)>();
cursor.seek(&offset, Bias::Left, &());
let overshoot = offset - cursor.seek_start();
*cursor.sum_start()
let overshoot = offset - cursor.start().0;
cursor.start().1
+ cursor
.item()
.map_or(Point::zero(), |chunk| chunk.to_point(overshoot))
@@ -137,17 +137,17 @@ impl Rope {
pub fn to_offset(&self, point: Point) -> usize {
assert!(point <= self.summary().lines);
let mut cursor = self.chunks.cursor::<Point, usize>();
let mut cursor = self.chunks.cursor::<(Point, usize)>();
cursor.seek(&point, Bias::Left, &());
let overshoot = point - cursor.seek_start();
cursor.sum_start() + cursor.item().map_or(0, |chunk| chunk.to_offset(overshoot))
let overshoot = point - cursor.start().0;
cursor.start().1 + cursor.item().map_or(0, |chunk| chunk.to_offset(overshoot))
}
pub fn clip_offset(&self, mut offset: usize, bias: Bias) -> usize {
let mut cursor = self.chunks.cursor::<usize, ()>();
let mut cursor = self.chunks.cursor::<usize>();
cursor.seek(&offset, Bias::Left, &());
if let Some(chunk) = cursor.item() {
let mut ix = offset - cursor.seek_start();
let mut ix = offset - cursor.start();
while !chunk.0.is_char_boundary(ix) {
match bias {
Bias::Left => {
@@ -167,11 +167,11 @@ impl Rope {
}
pub fn clip_point(&self, point: Point, bias: Bias) -> Point {
let mut cursor = self.chunks.cursor::<Point, ()>();
let mut cursor = self.chunks.cursor::<Point>();
cursor.seek(&point, Bias::Right, &());
if let Some(chunk) = cursor.item() {
let overshoot = point - cursor.seek_start();
*cursor.seek_start() + chunk.clip_point(overshoot, bias)
let overshoot = point - cursor.start();
*cursor.start() + chunk.clip_point(overshoot, bias)
} else {
self.summary().lines
}
@@ -194,7 +194,7 @@ impl Into<String> for Rope {
pub struct Cursor<'a> {
rope: &'a Rope,
chunks: sum_tree::Cursor<'a, Chunk, usize, ()>,
chunks: sum_tree::Cursor<'a, Chunk, usize>,
offset: usize,
}
@@ -226,18 +226,18 @@ impl<'a> Cursor<'a> {
let mut slice = Rope::new();
if let Some(start_chunk) = self.chunks.item() {
let start_ix = self.offset - self.chunks.seek_start();
let end_ix = cmp::min(end_offset, self.chunks.seek_end(&())) - self.chunks.seek_start();
let start_ix = self.offset - self.chunks.start();
let end_ix = cmp::min(end_offset, self.chunks.end(&())) - self.chunks.start();
slice.push(&start_chunk.0[start_ix..end_ix]);
}
if end_offset > self.chunks.seek_end(&()) {
if end_offset > self.chunks.end(&()) {
self.chunks.next(&());
slice.append(Rope {
chunks: self.chunks.slice(&end_offset, Bias::Right, &()),
});
if let Some(end_chunk) = self.chunks.item() {
let end_ix = end_offset - self.chunks.seek_start();
let end_ix = end_offset - self.chunks.start();
slice.push(&end_chunk.0[..end_ix]);
}
}
@@ -251,16 +251,16 @@ impl<'a> Cursor<'a> {
let mut summary = TextSummary::default();
if let Some(start_chunk) = self.chunks.item() {
let start_ix = self.offset - self.chunks.seek_start();
let end_ix = cmp::min(end_offset, self.chunks.seek_end(&())) - self.chunks.seek_start();
let start_ix = self.offset - self.chunks.start();
let end_ix = cmp::min(end_offset, self.chunks.end(&())) - self.chunks.start();
summary = TextSummary::from(&start_chunk.0[start_ix..end_ix]);
}
if end_offset > self.chunks.seek_end(&()) {
if end_offset > self.chunks.end(&()) {
self.chunks.next(&());
summary += &self.chunks.summary(&end_offset, Bias::Right, &());
if let Some(end_chunk) = self.chunks.item() {
let end_ix = end_offset - self.chunks.seek_start();
let end_ix = end_offset - self.chunks.start();
summary += TextSummary::from(&end_chunk.0[..end_ix]);
}
}
@@ -278,7 +278,7 @@ impl<'a> Cursor<'a> {
}
pub struct Chunks<'a> {
chunks: sum_tree::Cursor<'a, Chunk, usize, ()>,
chunks: sum_tree::Cursor<'a, Chunk, usize>,
range: Range<usize>,
}
@@ -290,11 +290,11 @@ impl<'a> Chunks<'a> {
}
pub fn offset(&self) -> usize {
self.range.start.max(*self.chunks.seek_start())
self.range.start.max(*self.chunks.start())
}
pub fn seek(&mut self, offset: usize) {
if offset >= self.chunks.seek_end(&()) {
if offset >= self.chunks.end(&()) {
self.chunks.seek_forward(&offset, Bias::Right, &());
} else {
self.chunks.seek(&offset, Bias::Right, &());
@@ -304,10 +304,10 @@ impl<'a> Chunks<'a> {
pub fn peek(&self) -> Option<&'a str> {
if let Some(chunk) = self.chunks.item() {
let offset = *self.chunks.seek_start();
let offset = *self.chunks.start();
if self.range.end > offset {
let start = self.range.start.saturating_sub(*self.chunks.seek_start());
let end = self.range.end - self.chunks.seek_start();
let start = self.range.start.saturating_sub(*self.chunks.start());
let end = self.range.end - self.chunks.start();
return Some(&chunk.0[start..chunk.0.len().min(end)]);
}
}
@@ -486,12 +486,6 @@ impl std::ops::AddAssign<Self> for TextSummary {
}
}
impl<'a> sum_tree::Dimension<'a, TextSummary> for TextSummary {
fn add_summary(&mut self, summary: &'a TextSummary, _: &()) {
*self += summary;
}
}
impl<'a> sum_tree::Dimension<'a, TextSummary> for usize {
fn add_summary(&mut self, summary: &'a TextSummary, _: &()) {
*self += summary.bytes;
@@ -611,7 +605,7 @@ mod tests {
impl Rope {
fn text(&self) -> String {
let mut text = String::new();
for chunk in self.chunks.cursor::<(), ()>() {
for chunk in self.chunks.cursor::<()>() {
text.push_str(&chunk.0);
}
text
+89 -92
View File
@@ -41,33 +41,35 @@ impl FoldPoint {
}
pub fn to_buffer_point(&self, snapshot: &Snapshot) -> Point {
let mut cursor = snapshot.transforms.cursor::<FoldPoint, Point>();
let mut cursor = snapshot.transforms.cursor::<(FoldPoint, Point)>();
cursor.seek(self, Bias::Right, &());
let overshoot = self.0 - cursor.seek_start().0;
*cursor.sum_start() + overshoot
let overshoot = self.0 - cursor.start().0 .0;
cursor.start().1 + overshoot
}
pub fn to_buffer_offset(&self, snapshot: &Snapshot) -> usize {
let mut cursor = snapshot.transforms.cursor::<FoldPoint, Point>();
let mut cursor = snapshot.transforms.cursor::<(FoldPoint, Point)>();
cursor.seek(self, Bias::Right, &());
let overshoot = self.0 - cursor.seek_start().0;
let overshoot = self.0 - cursor.start().0 .0;
snapshot
.buffer_snapshot
.to_offset(*cursor.sum_start() + overshoot)
.to_offset(cursor.start().1 + overshoot)
}
pub fn to_offset(&self, snapshot: &Snapshot) -> FoldOffset {
let mut cursor = snapshot.transforms.cursor::<FoldPoint, TransformSummary>();
let mut cursor = snapshot
.transforms
.cursor::<(FoldPoint, TransformSummary)>();
cursor.seek(self, Bias::Right, &());
let overshoot = self.0 - cursor.sum_start().output.lines;
let mut offset = cursor.sum_start().output.bytes;
let overshoot = self.0 - cursor.start().1.output.lines;
let mut offset = cursor.start().1.output.bytes;
if !overshoot.is_zero() {
let transform = cursor.item().expect("display point out of range");
assert!(transform.output_text.is_none());
let end_buffer_offset = snapshot
.buffer_snapshot
.to_offset(cursor.sum_start().input.lines + overshoot);
offset += end_buffer_offset - cursor.sum_start().input.bytes;
.to_offset(cursor.start().1.input.lines + overshoot);
offset += end_buffer_offset - cursor.start().1.input.bytes;
}
FoldOffset(offset)
}
@@ -75,19 +77,19 @@ impl FoldPoint {
impl Point {
pub fn to_fold_point(&self, snapshot: &Snapshot, bias: Bias) -> FoldPoint {
let mut cursor = snapshot.transforms.cursor::<Point, FoldPoint>();
let mut cursor = snapshot.transforms.cursor::<(Point, FoldPoint)>();
cursor.seek(self, Bias::Right, &());
if cursor.item().map_or(false, |t| t.is_fold()) {
if bias == Bias::Left || *self == *cursor.seek_start() {
*cursor.sum_start()
if bias == Bias::Left || *self == cursor.start().0 {
cursor.start().1
} else {
cursor.sum_end(&())
cursor.end(&()).1
}
} else {
let overshoot = *self - cursor.seek_start();
let overshoot = *self - cursor.start().0;
FoldPoint(cmp::min(
cursor.sum_start().0 + overshoot,
cursor.sum_end(&()).0,
cursor.start().1 .0 + overshoot,
cursor.end(&()).1 .0,
))
}
}
@@ -117,11 +119,11 @@ impl<'a> FoldMapWriter<'a> {
}
}
folds.sort_unstable_by(|a, b| sum_tree::SeekDimension::cmp(a, b, &buffer));
folds.sort_unstable_by(|a, b| sum_tree::SeekTarget::cmp(a, b, &buffer));
self.0.folds = {
let mut new_tree = SumTree::new();
let mut cursor = self.0.folds.cursor::<_, ()>();
let mut cursor = self.0.folds.cursor::<Fold>();
for fold in folds {
new_tree.push_tree(cursor.slice(&fold, Bias::Right, &buffer), &buffer);
new_tree.push(fold, &buffer);
@@ -168,7 +170,7 @@ impl<'a> FoldMapWriter<'a> {
fold_ixs_to_delete.dedup();
self.0.folds = {
let mut cursor = self.0.folds.cursor::<_, ()>();
let mut cursor = self.0.folds.cursor::<usize>();
let mut folds = SumTree::new();
for fold_ix in fold_ixs_to_delete {
folds.push_tree(cursor.slice(&fold_ix, Bias::Right, &buffer), &buffer);
@@ -287,20 +289,20 @@ impl FoldMap {
let mut new_transforms = SumTree::new();
let mut transforms = self.transforms.lock();
let mut cursor = transforms.cursor::<usize, ()>();
let mut cursor = transforms.cursor::<usize>();
cursor.seek(&0, Bias::Right, &());
while let Some(mut edit) = buffer_edits_iter.next() {
new_transforms.push_tree(cursor.slice(&edit.old_bytes.start, Bias::Left, &()), &());
edit.new_bytes.start -= edit.old_bytes.start - cursor.seek_start();
edit.old_bytes.start = *cursor.seek_start();
edit.new_bytes.start -= edit.old_bytes.start - cursor.start();
edit.old_bytes.start = *cursor.start();
cursor.seek(&edit.old_bytes.end, Bias::Right, &());
cursor.next(&());
let mut delta = edit.delta();
loop {
edit.old_bytes.end = *cursor.seek_start();
edit.old_bytes.end = *cursor.start();
if let Some(next_edit) = buffer_edits_iter.peek() {
if next_edit.old_bytes.start > edit.old_bytes.end {
@@ -324,7 +326,7 @@ impl FoldMap {
((edit.new_bytes.start + edit.deleted_bytes()) as isize + delta) as usize;
let anchor = buffer.anchor_before(edit.new_bytes.start);
let mut folds_cursor = self.folds.cursor::<_, ()>();
let mut folds_cursor = self.folds.cursor::<Fold>();
folds_cursor.seek(&Fold(anchor..Anchor::max()), Bias::Left, &buffer);
let mut folds = iter::from_fn({
@@ -432,39 +434,39 @@ impl FoldMap {
let mut fold_edits = Vec::with_capacity(buffer_edits.len());
{
let mut old_transforms = transforms.cursor::<usize, FoldOffset>();
let mut new_transforms = new_transforms.cursor::<usize, FoldOffset>();
let mut old_transforms = transforms.cursor::<(usize, FoldOffset)>();
let mut new_transforms = new_transforms.cursor::<(usize, FoldOffset)>();
for mut edit in buffer_edits {
old_transforms.seek(&edit.old_bytes.start, Bias::Left, &());
if old_transforms.item().map_or(false, |t| t.is_fold()) {
edit.old_bytes.start = *old_transforms.seek_start();
edit.old_bytes.start = old_transforms.start().0;
}
let old_start = old_transforms.sum_start().0
+ (edit.old_bytes.start - old_transforms.seek_start());
let old_start =
old_transforms.start().1 .0 + (edit.old_bytes.start - old_transforms.start().0);
old_transforms.seek_forward(&edit.old_bytes.end, Bias::Right, &());
if old_transforms.item().map_or(false, |t| t.is_fold()) {
old_transforms.next(&());
edit.old_bytes.end = *old_transforms.seek_start();
edit.old_bytes.end = old_transforms.start().0;
}
let old_end = old_transforms.sum_start().0
+ (edit.old_bytes.end - old_transforms.seek_start());
let old_end =
old_transforms.start().1 .0 + (edit.old_bytes.end - old_transforms.start().0);
new_transforms.seek(&edit.new_bytes.start, Bias::Left, &());
if new_transforms.item().map_or(false, |t| t.is_fold()) {
edit.new_bytes.start = *new_transforms.seek_start();
edit.new_bytes.start = new_transforms.start().0;
}
let new_start = new_transforms.sum_start().0
+ (edit.new_bytes.start - new_transforms.seek_start());
let new_start =
new_transforms.start().1 .0 + (edit.new_bytes.start - new_transforms.start().0);
new_transforms.seek_forward(&edit.new_bytes.end, Bias::Right, &());
if new_transforms.item().map_or(false, |t| t.is_fold()) {
new_transforms.next(&());
edit.new_bytes.end = *new_transforms.seek_start();
edit.new_bytes.end = new_transforms.start().0;
}
let new_end = new_transforms.sum_start().0
+ (edit.new_bytes.end - new_transforms.seek_start());
let new_end =
new_transforms.start().1 .0 + (edit.new_bytes.end - new_transforms.start().0);
fold_edits.push(FoldEdit {
old_bytes: FoldOffset(old_start)..FoldOffset(old_end),
@@ -503,38 +505,37 @@ impl Snapshot {
pub fn text_summary_for_range(&self, range: Range<FoldPoint>) -> TextSummary {
let mut summary = TextSummary::default();
let mut cursor = self.transforms.cursor::<FoldPoint, Point>();
let mut cursor = self.transforms.cursor::<(FoldPoint, Point)>();
cursor.seek(&range.start, Bias::Right, &());
if let Some(transform) = cursor.item() {
let start_in_transform = range.start.0 - cursor.seek_start().0;
let end_in_transform =
cmp::min(range.end, cursor.seek_end(&())).0 - cursor.seek_start().0;
let start_in_transform = range.start.0 - cursor.start().0 .0;
let end_in_transform = cmp::min(range.end, cursor.end(&()).0).0 - cursor.start().0 .0;
if let Some(output_text) = transform.output_text {
summary = TextSummary::from(
&output_text
[start_in_transform.column as usize..end_in_transform.column as usize],
);
} else {
let buffer_start = *cursor.sum_start() + start_in_transform;
let buffer_end = *cursor.sum_start() + end_in_transform;
let buffer_start = cursor.start().1 + start_in_transform;
let buffer_end = cursor.start().1 + end_in_transform;
summary = self
.buffer_snapshot
.text_summary_for_range(buffer_start..buffer_end);
}
}
if range.end > cursor.seek_end(&()) {
if range.end > cursor.end(&()).0 {
cursor.next(&());
summary += &cursor
.summary::<TransformSummary>(&range.end, Bias::Right, &())
.summary::<_, TransformSummary>(&range.end, Bias::Right, &())
.output;
if let Some(transform) = cursor.item() {
let end_in_transform = range.end.0 - cursor.seek_start().0;
let end_in_transform = range.end.0 - cursor.start().0 .0;
if let Some(output_text) = transform.output_text {
summary += TextSummary::from(&output_text[..end_in_transform.column as usize]);
} else {
let buffer_start = *cursor.sum_start();
let buffer_end = *cursor.sum_start() + end_in_transform;
let buffer_start = cursor.start().1;
let buffer_end = cursor.start().1 + end_in_transform;
summary += self
.buffer_snapshot
.text_summary_for_range(buffer_start..buffer_end);
@@ -600,19 +601,19 @@ impl Snapshot {
T: ToOffset,
{
let offset = offset.to_offset(&self.buffer_snapshot);
let mut cursor = self.transforms.cursor::<usize, ()>();
let mut cursor = self.transforms.cursor::<usize>();
cursor.seek(&offset, Bias::Right, &());
cursor.item().map_or(false, |t| t.output_text.is_some())
}
pub fn is_line_folded(&self, output_row: u32) -> bool {
let mut cursor = self.transforms.cursor::<FoldPoint, ()>();
let mut cursor = self.transforms.cursor::<FoldPoint>();
cursor.seek(&FoldPoint::new(output_row, 0), Bias::Right, &());
while let Some(transform) = cursor.item() {
if transform.output_text.is_some() {
return true;
}
if cursor.seek_end(&()).row() == output_row {
if cursor.end(&()).row() == output_row {
cursor.next(&())
} else {
break;
@@ -622,10 +623,10 @@ impl Snapshot {
}
pub fn chunks_at(&self, offset: FoldOffset) -> Chunks {
let mut transform_cursor = self.transforms.cursor::<FoldOffset, usize>();
let mut transform_cursor = self.transforms.cursor::<(FoldOffset, usize)>();
transform_cursor.seek(&offset, Bias::Right, &());
let overshoot = offset.0 - transform_cursor.seek_start().0;
let buffer_offset = transform_cursor.sum_start() + overshoot;
let overshoot = offset.0 - transform_cursor.start().0 .0;
let buffer_offset = transform_cursor.start().1 + overshoot;
Chunks {
transform_cursor,
buffer_offset,
@@ -636,15 +637,15 @@ impl Snapshot {
}
pub fn highlighted_chunks(&mut self, range: Range<FoldOffset>) -> HighlightedChunks {
let mut transform_cursor = self.transforms.cursor::<FoldOffset, usize>();
let mut transform_cursor = self.transforms.cursor::<(FoldOffset, usize)>();
transform_cursor.seek(&range.end, Bias::Right, &());
let overshoot = range.end.0 - transform_cursor.seek_start().0;
let buffer_end = transform_cursor.sum_start() + overshoot;
let overshoot = range.end.0 - transform_cursor.start().0 .0;
let buffer_end = transform_cursor.start().1 + overshoot;
transform_cursor.seek(&range.start, Bias::Right, &());
let overshoot = range.start.0 - transform_cursor.seek_start().0;
let buffer_start = transform_cursor.sum_start() + overshoot;
let overshoot = range.start.0 - transform_cursor.start().0 .0;
let buffer_start = transform_cursor.start().1 + overshoot;
HighlightedChunks {
transform_cursor,
@@ -663,19 +664,19 @@ impl Snapshot {
#[cfg(test)]
pub fn clip_offset(&self, offset: FoldOffset, bias: Bias) -> FoldOffset {
let mut cursor = self.transforms.cursor::<FoldOffset, usize>();
let mut cursor = self.transforms.cursor::<(FoldOffset, usize)>();
cursor.seek(&offset, Bias::Right, &());
if let Some(transform) = cursor.item() {
let transform_start = cursor.seek_start().0;
let transform_start = cursor.start().0 .0;
if transform.output_text.is_some() {
if offset.0 == transform_start || matches!(bias, Bias::Left) {
FoldOffset(transform_start)
} else {
FoldOffset(cursor.seek_end(&()).0)
FoldOffset(cursor.end(&()).0 .0)
}
} else {
let overshoot = offset.0 - transform_start;
let buffer_offset = cursor.sum_start() + overshoot;
let buffer_offset = cursor.start().1 + overshoot;
let clipped_buffer_offset = self.buffer_snapshot.clip_offset(buffer_offset, bias);
FoldOffset(
(offset.0 as isize + (clipped_buffer_offset as isize - buffer_offset as isize))
@@ -688,19 +689,19 @@ impl Snapshot {
}
pub fn clip_point(&self, point: FoldPoint, bias: Bias) -> FoldPoint {
let mut cursor = self.transforms.cursor::<FoldPoint, Point>();
let mut cursor = self.transforms.cursor::<(FoldPoint, Point)>();
cursor.seek(&point, Bias::Right, &());
if let Some(transform) = cursor.item() {
let transform_start = cursor.seek_start().0;
let transform_start = cursor.start().0 .0;
if transform.output_text.is_some() {
if point.0 == transform_start || matches!(bias, Bias::Left) {
FoldPoint(transform_start)
} else {
FoldPoint(cursor.seek_end(&()).0)
FoldPoint(cursor.end(&()).0 .0)
}
} else {
let overshoot = point.0 - transform_start;
let buffer_position = *cursor.sum_start() + overshoot;
let buffer_position = cursor.start().1 + overshoot;
let clipped_buffer_position =
self.buffer_snapshot.clip_point(buffer_position, bias);
FoldPoint::new(
@@ -822,12 +823,6 @@ impl sum_tree::Summary for TransformSummary {
}
}
impl<'a> sum_tree::Dimension<'a, TransformSummary> for TransformSummary {
fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) {
sum_tree::Summary::add_summary(self, summary, &());
}
}
#[derive(Clone, Debug)]
struct Fold(Range<Anchor>);
@@ -905,7 +900,7 @@ impl<'a> sum_tree::Dimension<'a, FoldSummary> for Fold {
}
}
impl<'a> sum_tree::SeekDimension<'a, FoldSummary> for Fold {
impl<'a> sum_tree::SeekTarget<'a, FoldSummary, Fold> for Fold {
fn cmp(&self, other: &Self, buffer: &buffer::Snapshot) -> Ordering {
self.0.cmp(&other.0, buffer).unwrap()
}
@@ -918,7 +913,7 @@ impl<'a> sum_tree::Dimension<'a, FoldSummary> for usize {
}
pub struct BufferRows<'a> {
cursor: Cursor<'a, Transform, FoldPoint, Point>,
cursor: Cursor<'a, Transform, (FoldPoint, Point)>,
fold_point: FoldPoint,
}
@@ -926,7 +921,7 @@ impl<'a> Iterator for BufferRows<'a> {
type Item = u32;
fn next(&mut self) -> Option<Self::Item> {
while self.fold_point > self.cursor.seek_end(&()) {
while self.fold_point > self.cursor.end(&()).0 {
self.cursor.next(&());
if self.cursor.item().is_none() {
// TODO: Return a bool from next?
@@ -935,8 +930,8 @@ impl<'a> Iterator for BufferRows<'a> {
}
if self.cursor.item().is_some() {
let overshoot = self.fold_point.0 - self.cursor.seek_start().0;
let buffer_point = *self.cursor.sum_start() + overshoot;
let overshoot = self.fold_point.0 - self.cursor.start().0 .0;
let buffer_point = self.cursor.start().1 + overshoot;
*self.fold_point.row_mut() += 1;
Some(buffer_point.row)
} else {
@@ -946,7 +941,7 @@ impl<'a> Iterator for BufferRows<'a> {
}
pub struct Chunks<'a> {
transform_cursor: Cursor<'a, Transform, FoldOffset, usize>,
transform_cursor: Cursor<'a, Transform, (FoldOffset, usize)>,
buffer_chunks: buffer::Chunks<'a>,
buffer_offset: usize,
}
@@ -967,7 +962,7 @@ impl<'a> Iterator for Chunks<'a> {
self.buffer_offset += transform.summary.input.bytes;
self.buffer_chunks.seek(self.buffer_offset);
while self.buffer_offset >= self.transform_cursor.sum_end(&())
while self.buffer_offset >= self.transform_cursor.end(&()).1
&& self.transform_cursor.item().is_some()
{
self.transform_cursor.next(&());
@@ -982,7 +977,7 @@ impl<'a> Iterator for Chunks<'a> {
chunk = &chunk[offset_in_chunk..];
// Truncate the chunk so that it ends at the next fold.
let region_end = self.transform_cursor.sum_end(&()) - self.buffer_offset;
let region_end = self.transform_cursor.end(&()).1 - self.buffer_offset;
if chunk.len() >= region_end {
chunk = &chunk[0..region_end];
self.transform_cursor.next(&());
@@ -999,7 +994,7 @@ impl<'a> Iterator for Chunks<'a> {
}
pub struct HighlightedChunks<'a> {
transform_cursor: Cursor<'a, Transform, FoldOffset, usize>,
transform_cursor: Cursor<'a, Transform, (FoldOffset, usize)>,
buffer_chunks: buffer::HighlightedChunks<'a>,
buffer_chunk: Option<(usize, &'a str, HighlightId)>,
buffer_offset: usize,
@@ -1022,7 +1017,7 @@ impl<'a> Iterator for HighlightedChunks<'a> {
self.buffer_offset += transform.summary.input.bytes;
self.buffer_chunks.seek(self.buffer_offset);
while self.buffer_offset >= self.transform_cursor.sum_end(&())
while self.buffer_offset >= self.transform_cursor.end(&()).1
&& self.transform_cursor.item().is_some()
{
self.transform_cursor.next(&());
@@ -1046,7 +1041,7 @@ impl<'a> Iterator for HighlightedChunks<'a> {
chunk = &chunk[offset_in_chunk..];
// Truncate the chunk so that it ends at the next fold.
let region_end = self.transform_cursor.sum_end(&()) - self.buffer_offset;
let region_end = self.transform_cursor.end(&()).1 - self.buffer_offset;
if chunk.len() >= region_end {
chunk = &chunk[0..region_end];
self.transform_cursor.next(&());
@@ -1073,16 +1068,18 @@ pub struct FoldOffset(pub usize);
impl FoldOffset {
pub fn to_point(&self, snapshot: &Snapshot) -> FoldPoint {
let mut cursor = snapshot.transforms.cursor::<FoldOffset, TransformSummary>();
let mut cursor = snapshot
.transforms
.cursor::<(FoldOffset, TransformSummary)>();
cursor.seek(self, Bias::Right, &());
let overshoot = if cursor.item().map_or(true, |t| t.is_fold()) {
Point::new(0, (self.0 - cursor.seek_start().0) as u32)
Point::new(0, (self.0 - cursor.start().0 .0) as u32)
} else {
let buffer_offset = cursor.sum_start().input.bytes + self.0 - cursor.seek_start().0;
let buffer_offset = cursor.start().1.input.bytes + self.0 - cursor.start().0 .0;
let buffer_point = snapshot.buffer_snapshot.to_point(buffer_offset);
buffer_point - cursor.sum_start().input.lines
buffer_point - cursor.start().1.input.lines
};
FoldPoint(cursor.sum_start().output.lines + overshoot)
FoldPoint(cursor.start().1.output.lines + overshoot)
}
}
+39 -39
View File
@@ -51,7 +51,7 @@ pub struct Chunks<'a> {
input_chunks: tab_map::Chunks<'a>,
input_chunk: &'a str,
output_position: WrapPoint,
transforms: Cursor<'a, Transform, WrapPoint, TabPoint>,
transforms: Cursor<'a, Transform, (WrapPoint, TabPoint)>,
}
pub struct HighlightedChunks<'a> {
@@ -60,7 +60,7 @@ pub struct HighlightedChunks<'a> {
style_id: HighlightId,
output_position: WrapPoint,
max_output_row: u32,
transforms: Cursor<'a, Transform, WrapPoint, TabPoint>,
transforms: Cursor<'a, Transform, (WrapPoint, TabPoint)>,
}
pub struct BufferRows<'a> {
@@ -69,7 +69,7 @@ pub struct BufferRows<'a> {
output_row: u32,
soft_wrapped: bool,
max_output_row: u32,
transforms: Cursor<'a, Transform, WrapPoint, TabPoint>,
transforms: Cursor<'a, Transform, (WrapPoint, TabPoint)>,
}
impl WrapMap {
@@ -272,7 +272,7 @@ impl Snapshot {
if edits.is_empty() {
new_transforms = self.transforms.clone();
} else {
let mut old_cursor = self.transforms.cursor::<TabPoint, ()>();
let mut old_cursor = self.transforms.cursor::<TabPoint>();
let mut edits = edits.into_iter().peekable();
new_transforms =
old_cursor.slice(&edits.peek().unwrap().old_lines.start, Bias::Right, &());
@@ -293,11 +293,11 @@ impl Snapshot {
old_cursor.seek_forward(&edit.old_lines.end, Bias::Right, &());
if let Some(next_edit) = edits.peek() {
if next_edit.old_lines.start > old_cursor.seek_end(&()) {
if old_cursor.seek_end(&()) > edit.old_lines.end {
let summary = self.tab_snapshot.text_summary_for_range(
edit.old_lines.end..old_cursor.seek_end(&()),
);
if next_edit.old_lines.start > old_cursor.end(&()) {
if old_cursor.end(&()) > edit.old_lines.end {
let summary = self
.tab_snapshot
.text_summary_for_range(edit.old_lines.end..old_cursor.end(&()));
new_transforms.push_or_extend(Transform::isomorphic(summary));
}
old_cursor.next(&());
@@ -307,10 +307,10 @@ impl Snapshot {
);
}
} else {
if old_cursor.seek_end(&()) > edit.old_lines.end {
if old_cursor.end(&()) > edit.old_lines.end {
let summary = self
.tab_snapshot
.text_summary_for_range(edit.old_lines.end..old_cursor.seek_end(&()));
.text_summary_for_range(edit.old_lines.end..old_cursor.end(&()));
new_transforms.push_or_extend(Transform::isomorphic(summary));
}
old_cursor.next(&());
@@ -364,7 +364,7 @@ impl Snapshot {
new_transforms = self.transforms.clone();
} else {
let mut row_edits = row_edits.into_iter().peekable();
let mut old_cursor = self.transforms.cursor::<TabPoint, ()>();
let mut old_cursor = self.transforms.cursor::<TabPoint>();
new_transforms = old_cursor.slice(
&TabPoint::new(row_edits.peek().unwrap().old_rows.start, 0),
@@ -427,10 +427,10 @@ impl Snapshot {
old_cursor.seek_forward(&TabPoint::new(edit.old_rows.end, 0), Bias::Right, &());
if let Some(next_edit) = row_edits.peek() {
if next_edit.old_rows.start > old_cursor.seek_end(&()).row() {
if old_cursor.seek_end(&()) > TabPoint::new(edit.old_rows.end, 0) {
if next_edit.old_rows.start > old_cursor.end(&()).row() {
if old_cursor.end(&()) > TabPoint::new(edit.old_rows.end, 0) {
let summary = self.tab_snapshot.text_summary_for_range(
TabPoint::new(edit.old_rows.end, 0)..old_cursor.seek_end(&()),
TabPoint::new(edit.old_rows.end, 0)..old_cursor.end(&()),
);
new_transforms.push_or_extend(Transform::isomorphic(summary));
}
@@ -445,9 +445,9 @@ impl Snapshot {
);
}
} else {
if old_cursor.seek_end(&()) > TabPoint::new(edit.old_rows.end, 0) {
if old_cursor.end(&()) > TabPoint::new(edit.old_rows.end, 0) {
let summary = self.tab_snapshot.text_summary_for_range(
TabPoint::new(edit.old_rows.end, 0)..old_cursor.seek_end(&()),
TabPoint::new(edit.old_rows.end, 0)..old_cursor.end(&()),
);
new_transforms.push_or_extend(Transform::isomorphic(summary));
}
@@ -465,11 +465,11 @@ impl Snapshot {
pub fn chunks_at(&self, wrap_row: u32) -> Chunks {
let point = WrapPoint::new(wrap_row, 0);
let mut transforms = self.transforms.cursor::<WrapPoint, TabPoint>();
let mut transforms = self.transforms.cursor::<(WrapPoint, TabPoint)>();
transforms.seek(&point, Bias::Right, &());
let mut input_position = TabPoint(transforms.sum_start().0);
let mut input_position = TabPoint(transforms.start().1 .0);
if transforms.item().map_or(false, |t| t.is_isomorphic()) {
input_position.0 += point.0 - transforms.seek_start().0;
input_position.0 += point.0 - transforms.start().0 .0;
}
let input_chunks = self.tab_snapshot.chunks_at(input_position);
Chunks {
@@ -483,11 +483,11 @@ impl Snapshot {
pub fn highlighted_chunks_for_rows(&mut self, rows: Range<u32>) -> HighlightedChunks {
let output_start = WrapPoint::new(rows.start, 0);
let output_end = WrapPoint::new(rows.end, 0);
let mut transforms = self.transforms.cursor::<WrapPoint, TabPoint>();
let mut transforms = self.transforms.cursor::<(WrapPoint, TabPoint)>();
transforms.seek(&output_start, Bias::Right, &());
let mut input_start = TabPoint(transforms.sum_start().0);
let mut input_start = TabPoint(transforms.start().1 .0);
if transforms.item().map_or(false, |t| t.is_isomorphic()) {
input_start.0 += output_start.0 - transforms.seek_start().0;
input_start.0 += output_start.0 - transforms.start().0 .0;
}
let input_end = self
.to_tab_point(output_end)
@@ -520,7 +520,7 @@ impl Snapshot {
}
pub fn soft_wrap_indent(&self, row: u32) -> Option<u32> {
let mut cursor = self.transforms.cursor::<_, ()>();
let mut cursor = self.transforms.cursor::<WrapPoint>();
cursor.seek(&WrapPoint::new(row + 1, 0), Bias::Right, &());
cursor.item().and_then(|transform| {
if transform.is_isomorphic() {
@@ -536,11 +536,11 @@ impl Snapshot {
}
pub fn buffer_rows(&self, start_row: u32) -> BufferRows {
let mut transforms = self.transforms.cursor::<WrapPoint, TabPoint>();
let mut transforms = self.transforms.cursor::<(WrapPoint, TabPoint)>();
transforms.seek(&WrapPoint::new(start_row, 0), Bias::Left, &());
let mut input_row = transforms.sum_start().row();
let mut input_row = transforms.start().1.row();
if transforms.item().map_or(false, |t| t.is_isomorphic()) {
input_row += start_row - transforms.seek_start().row();
input_row += start_row - transforms.start().0.row();
}
let soft_wrapped = transforms.item().map_or(false, |t| !t.is_isomorphic());
let mut input_buffer_rows = self.tab_snapshot.buffer_rows(input_row);
@@ -556,27 +556,27 @@ impl Snapshot {
}
pub fn to_tab_point(&self, point: WrapPoint) -> TabPoint {
let mut cursor = self.transforms.cursor::<WrapPoint, TabPoint>();
let mut cursor = self.transforms.cursor::<(WrapPoint, TabPoint)>();
cursor.seek(&point, Bias::Right, &());
let mut tab_point = cursor.sum_start().0;
let mut tab_point = cursor.start().1 .0;
if cursor.item().map_or(false, |t| t.is_isomorphic()) {
tab_point += point.0 - cursor.seek_start().0;
tab_point += point.0 - cursor.start().0 .0;
}
TabPoint(tab_point)
}
pub fn to_wrap_point(&self, point: TabPoint) -> WrapPoint {
let mut cursor = self.transforms.cursor::<TabPoint, WrapPoint>();
let mut cursor = self.transforms.cursor::<(TabPoint, WrapPoint)>();
cursor.seek(&point, Bias::Right, &());
WrapPoint(cursor.sum_start().0 + (point.0 - cursor.seek_start().0))
WrapPoint(cursor.start().1 .0 + (point.0 - cursor.start().0 .0))
}
pub fn clip_point(&self, mut point: WrapPoint, bias: Bias) -> WrapPoint {
if bias == Bias::Left {
let mut cursor = self.transforms.cursor::<WrapPoint, ()>();
let mut cursor = self.transforms.cursor::<WrapPoint>();
cursor.seek(&point, Bias::Right, &());
if cursor.item().map_or(false, |t| !t.is_isomorphic()) {
point = *cursor.seek_start();
point = *cursor.start();
*point.column_mut() -= 1;
}
}
@@ -593,7 +593,7 @@ impl Snapshot {
);
{
let mut transforms = self.transforms.cursor::<(), ()>().peekable();
let mut transforms = self.transforms.cursor::<()>().peekable();
while let Some(transform) = transforms.next() {
if let Some(next_transform) = transforms.peek() {
assert!(transform.is_isomorphic() != next_transform.is_isomorphic());
@@ -638,7 +638,7 @@ impl<'a> Iterator for Chunks<'a> {
fn next(&mut self) -> Option<Self::Item> {
let transform = self.transforms.item()?;
if let Some(display_text) = transform.display_text {
if self.output_position > *self.transforms.seek_start() {
if self.output_position > self.transforms.start().0 {
self.output_position.0.column += transform.summary.output.lines.column;
self.transforms.next(&());
return Some(&display_text[1..]);
@@ -654,7 +654,7 @@ impl<'a> Iterator for Chunks<'a> {
}
let mut input_len = 0;
let transform_end = self.transforms.seek_end(&());
let transform_end = self.transforms.end(&()).0;
for c in self.input_chunk.chars() {
let char_len = c.len_utf8();
input_len += char_len;
@@ -691,7 +691,7 @@ impl<'a> Iterator for HighlightedChunks<'a> {
let mut end_ix = display_text.len();
let mut summary = transform.summary.output.lines;
if self.output_position > *self.transforms.seek_start() {
if self.output_position > self.transforms.start().0 {
// Exclude newline starting prior to the desired row.
start_ix = 1;
summary.row = 0;
@@ -713,7 +713,7 @@ impl<'a> Iterator for HighlightedChunks<'a> {
}
let mut input_len = 0;
let transform_end = self.transforms.seek_end(&());
let transform_end = self.transforms.end(&()).0;
for c in self.input_chunk.chars() {
let char_len = c.len_utf8();
input_len += char_len;
+19 -19
View File
@@ -1140,7 +1140,7 @@ impl LocalWorktree {
remote_id.await.map(|id| {
let entries = snapshot
.entries_by_path
.cursor::<(), ()>()
.cursor::<()>()
.filter(|e| !e.is_ignored)
.map(Into::into)
.collect();
@@ -1385,12 +1385,12 @@ impl Snapshot {
let mut removed_entries = Vec::new();
let mut self_entries = self
.entries_by_id
.cursor::<(), ()>()
.cursor::<()>()
.filter(|e| include_ignored || !e.is_ignored)
.peekable();
let mut other_entries = other
.entries_by_id
.cursor::<(), ()>()
.cursor::<()>()
.filter(|e| include_ignored || !e.is_ignored)
.peekable();
loop {
@@ -1485,7 +1485,7 @@ impl Snapshot {
pub fn paths(&self) -> impl Iterator<Item = &Arc<Path>> {
let empty_path = Path::new("");
self.entries_by_path
.cursor::<(), ()>()
.cursor::<()>()
.filter(move |entry| entry.path.as_ref() != empty_path)
.map(|entry| &entry.path)
}
@@ -1507,7 +1507,7 @@ impl Snapshot {
}
fn entry_for_path(&self, path: impl AsRef<Path>) -> Option<&Entry> {
let mut cursor = self.entries_by_path.cursor::<_, ()>();
let mut cursor = self.entries_by_path.cursor::<PathSearch>();
if cursor.seek(&PathSearch::Exact(path.as_ref()), Bias::Left, &()) {
cursor.item()
} else {
@@ -1600,7 +1600,7 @@ impl Snapshot {
let mut new_entries;
let removed_entry_ids;
{
let mut cursor = self.entries_by_path.cursor::<_, ()>();
let mut cursor = self.entries_by_path.cursor::<PathSearch>();
new_entries = cursor.slice(&PathSearch::Exact(path), Bias::Left, &());
removed_entry_ids = cursor.slice(&PathSearch::Successor(path), Bias::Left, &());
new_entries.push_tree(cursor.suffix(&()), &());
@@ -1608,7 +1608,7 @@ impl Snapshot {
self.entries_by_path = new_entries;
let mut entries_by_id_edits = Vec::new();
for entry in removed_entry_ids.cursor::<(), ()>() {
for entry in removed_entry_ids.cursor::<()>() {
let removed_entry_id = self
.removed_entry_ids
.entry(entry.inode)
@@ -1655,7 +1655,7 @@ impl Snapshot {
impl fmt::Debug for Snapshot {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for entry in self.entries_by_path.cursor::<(), ()>() {
for entry in self.entries_by_path.cursor::<()>() {
for _ in entry.path.ancestors().skip(1) {
write!(f, " ")?;
}
@@ -2556,8 +2556,8 @@ impl WorktreeHandle for ModelHandle<Worktree> {
}
pub enum FileIter<'a> {
All(Cursor<'a, Entry, FileCount, ()>),
Visible(Cursor<'a, Entry, VisibleFileCount, ()>),
All(Cursor<'a, Entry, FileCount>),
Visible(Cursor<'a, Entry, VisibleFileCount>),
}
impl<'a> FileIter<'a> {
@@ -2576,12 +2576,12 @@ impl<'a> FileIter<'a> {
fn next_internal(&mut self) {
match self {
Self::All(cursor) => {
let ix = *cursor.seek_start();
cursor.seek_forward(&FileCount(ix.0 + 1), Bias::Right, &());
let ix = cursor.start().0;
cursor.seek_forward(&FileCount(ix + 1), Bias::Right, &());
}
Self::Visible(cursor) => {
let ix = *cursor.seek_start();
cursor.seek_forward(&VisibleFileCount(ix.0 + 1), Bias::Right, &());
let ix = cursor.start().0;
cursor.seek_forward(&VisibleFileCount(ix + 1), Bias::Right, &());
}
}
}
@@ -2609,7 +2609,7 @@ impl<'a> Iterator for FileIter<'a> {
struct ChildEntriesIter<'a> {
parent_path: &'a Path,
cursor: Cursor<'a, Entry, PathSearch<'a>, ()>,
cursor: Cursor<'a, Entry, PathSearch<'a>>,
}
impl<'a> ChildEntriesIter<'a> {
@@ -3244,7 +3244,7 @@ mod tests {
let mut entries_by_id_edits = Vec::new();
for entry in prev_snapshot
.entries_by_id
.cursor::<(), ()>()
.cursor::<()>()
.filter(|e| e.is_ignored)
{
entries_by_path_edits.push(Edit::Remove(PathKey(entry.path.clone())));
@@ -3419,7 +3419,7 @@ mod tests {
fn check_invariants(&self) {
let mut files = self.files(0);
let mut visible_files = self.visible_files(0);
for entry in self.entries_by_path.cursor::<(), ()>() {
for entry in self.entries_by_path.cursor::<()>() {
if entry.is_file() {
assert_eq!(files.next().unwrap().inode, entry.inode);
if !entry.is_ignored {
@@ -3442,7 +3442,7 @@ mod tests {
let dfs_paths = self
.entries_by_path
.cursor::<(), ()>()
.cursor::<()>()
.map(|e| e.path.as_ref())
.collect::<Vec<_>>();
assert_eq!(bfs_paths, dfs_paths);
@@ -3457,7 +3457,7 @@ mod tests {
fn to_vec(&self, include_ignored: bool) -> Vec<(&Path, u64, bool)> {
let mut paths = Vec::new();
for entry in self.entries_by_path.cursor::<(), ()>() {
for entry in self.entries_by_path.cursor::<()>() {
if include_ignored || !entry.is_ignored {
paths.push((entry.path.as_ref(), entry.inode, entry.is_ignored));
}