From f016400ddc1feb38cfd9a9dc14ede2c84efd449b Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 4 Jun 2021 12:34:35 +0200 Subject: [PATCH] Remove `FullOffset` --- zed/src/editor/buffer.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/zed/src/editor/buffer.rs b/zed/src/editor/buffer.rs index b189cddf0f..82e6818bfc 100644 --- a/zed/src/editor/buffer.rs +++ b/zed/src/editor/buffer.rs @@ -352,7 +352,7 @@ pub struct FragmentSummary { max_insertion_version: time::Global, } -#[derive(Default, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Default, Clone, Debug, PartialEq, Eq)] struct FragmentTextSummary { visible: usize, deleted: usize, @@ -1621,7 +1621,10 @@ impl Buffer { fn full_offset_for_anchor(&self, anchor: &Anchor) -> usize { match anchor { Anchor::Start => 0, - Anchor::End => self.fragments.extent::(&None).0, + Anchor::End => { + let summary = self.fragments.summary(); + summary.text.visible + summary.text.deleted + } Anchor::Middle { offset, bias, @@ -1629,14 +1632,15 @@ impl Buffer { } => { let mut cursor = self .fragments - .cursor::(); + .cursor::(); cursor.seek( &VersionedOffset::Offset(*offset), bias.to_seek_bias(), &Some(version.clone()), ); - let full_offset = cursor.start().1; - full_offset.0 + offset - cursor.start().0.offset() + let overshoot = offset - cursor.start().0.offset(); + let summary = cursor.start().1; + summary.visible + summary.deleted + overshoot } } } @@ -2135,15 +2139,6 @@ where } } -#[derive(Clone, Copy, Debug, Default)] -struct FullOffset(usize); - -impl<'a> sum_tree::Dimension<'a, FragmentSummary> for FullOffset { - fn add_summary(&mut self, summary: &'a FragmentSummary, _: &Option) { - self.0 += summary.text.visible + summary.text.deleted; - } -} - impl Operation { fn replica_id(&self) -> ReplicaId { self.lamport_timestamp().replica_id