From e193a660aa346ebcf1eb5f48ae7bc859ff4ba5f3 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 19 Jul 2021 13:59:07 -0600 Subject: [PATCH] WIP --- gpui/src/lib.rs | 3 ++- zed/src/editor/buffer/point.rs | 6 ++++++ zed/src/editor/display_map/fold_map.rs | 2 +- zed/src/editor/display_map/tab_map.rs | 20 +++++++++++++++++--- zed/src/editor/display_map/wrap_map.rs | 23 +++++++++++++---------- 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/gpui/src/lib.rs b/gpui/src/lib.rs index 955d35e7e0..591d220bba 100644 --- a/gpui/src/lib.rs +++ b/gpui/src/lib.rs @@ -25,7 +25,8 @@ pub mod json; pub mod keymap; mod platform; pub use gpui_macros::test; -pub use platform::{Event, FontSystem, PathPromptOptions, Platform, PromptLevel}; +pub use platform::FontSystem; +pub use platform::{Event, PathPromptOptions, Platform, PromptLevel}; pub use presenter::{ AfterLayoutContext, Axis, DebugContext, EventContext, LayoutContext, PaintContext, SizeConstraint, Vector2FExt, diff --git a/zed/src/editor/buffer/point.rs b/zed/src/editor/buffer/point.rs index 63deb052f6..04170c6990 100644 --- a/zed/src/editor/buffer/point.rs +++ b/zed/src/editor/buffer/point.rs @@ -72,6 +72,12 @@ impl Sub for Point { impl<'a> AddAssign<&'a Self> for Point { fn add_assign(&mut self, other: &'a Self) { + *self += *self; + } +} + +impl AddAssign for Point { + fn add_assign(&mut self, other: Self) { if other.row == 0 { self.column += other.column; } else { diff --git a/zed/src/editor/display_map/fold_map.rs b/zed/src/editor/display_map/fold_map.rs index c294ee5bc3..1d5f49810a 100644 --- a/zed/src/editor/display_map/fold_map.rs +++ b/zed/src/editor/display_map/fold_map.rs @@ -19,7 +19,7 @@ use std::{ }; #[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)] -pub struct OutputPoint(super::Point); +pub struct OutputPoint(pub super::Point); impl OutputPoint { pub fn new(row: u32, column: u32) -> Self { diff --git a/zed/src/editor/display_map/tab_map.rs b/zed/src/editor/display_map/tab_map.rs index 68ac493dd4..770a4df6de 100644 --- a/zed/src/editor/display_map/tab_map.rs +++ b/zed/src/editor/display_map/tab_map.rs @@ -4,7 +4,7 @@ use super::fold_map::{ Chunks as InputChunks, Edit as InputEdit, HighlightedChunks as InputHighlightedChunks, OutputOffset as InputOffset, OutputPoint as InputPoint, Snapshot as InputSnapshot, }; -use crate::{settings::StyleId, util::Bias}; +use crate::{editor::rope, settings::StyleId, util::Bias}; use std::{ mem, ops::{AddAssign, Range}, @@ -232,7 +232,7 @@ impl Snapshot { pub struct OutputOffset(pub usize); #[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)] -pub struct OutputPoint(super::Point); +pub struct OutputPoint(pub super::Point); impl OutputPoint { pub fn new(row: u32, column: u32) -> Self { @@ -262,7 +262,7 @@ impl OutputPoint { impl AddAssign for OutputPoint { fn add_assign(&mut self, rhs: Self) { - self.0 += rhs.0; + self.0 += &rhs.0; } } @@ -281,6 +281,20 @@ pub struct TextSummary { pub longest_row_chars: u32, } +impl<'a> From<&'a str> for TextSummary { + fn from(text: &'a str) -> Self { + let sum = rope::TextSummary::from(text); + + TextSummary { + lines: sum.lines, + first_line_chars: sum.first_line_chars, + last_line_chars: sum.last_line_chars, + longest_row: sum.longest_row, + longest_row_chars: sum.longest_row_chars, + } + } +} + impl<'a> std::ops::AddAssign<&'a Self> for TextSummary { fn add_assign(&mut self, other: &'a Self) { let joined_chars = self.last_line_chars + other.first_line_chars; diff --git a/zed/src/editor/display_map/wrap_map.rs b/zed/src/editor/display_map/wrap_map.rs index f6cf1c45b4..89d8b6ed06 100644 --- a/zed/src/editor/display_map/wrap_map.rs +++ b/zed/src/editor/display_map/wrap_map.rs @@ -1,6 +1,5 @@ use super::tab_map::{ - Edit as InputEdit, OutputOffset as InputOffset, OutputPoint as InputPoint, - Snapshot as InputSnapshot, TextSummary, + Edit as InputEdit, OutputPoint as InputPoint, Snapshot as InputSnapshot, TextSummary, }; use crate::{ editor::Point, @@ -200,11 +199,11 @@ impl BackgroundWrapper { &(), ); - for edit in edits { - if edit.new_rows.start > new_transforms.summary().input.row() { + while let Some(edit) = edits.next() { + if edit.new_rows.start > new_transforms.summary().input.lines.row { new_transforms.push( - Transform::isomorphic(new_snapshot.input.text_summary_for_rows( - new_transforms.summary().input.row()..edit.new_rows.start, + Transform::isomorphic(new_snapshot.text_summary_for_rows( + new_transforms.summary().input.lines.row..edit.new_rows.start, )), &(), ); @@ -238,7 +237,7 @@ impl BackgroundWrapper { } } - old_cursor.seek_forward(&edit.old_rows.end, Bias::Right, &()); + old_cursor.seek_forward(&InputPoint::new(edit.old_rows.end, 0), Bias::Right, &()); if let Some(next_edit) = edits.peek() { if next_edit.old_rows.start > old_cursor.seek_end(&()).row() { new_transforms.push( @@ -249,7 +248,11 @@ impl BackgroundWrapper { ); old_cursor.next(&()); new_transforms.push_tree( - old_cursor.slice(&next_edit.old_rows.start, Bias::Right, &()), + old_cursor.slice( + &InputPoint::new(next_edit.old_rows.start, 0), + Bias::Right, + &(), + ), &(), ); } @@ -330,7 +333,7 @@ impl sum_tree::Summary for TransformSummary { impl<'a> sum_tree::Dimension<'a, TransformSummary> for InputPoint { fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) { - *self += &InputPoint(summary.input.lines); + *self += InputPoint(summary.input.lines); } } @@ -392,7 +395,7 @@ mod tests { font_system.clone(), ); let edit = InputEdit { - old_lines: Default::default()..Default::default(), + old_lines: Default::default()..tabs_snapshot.max_point(), new_lines: Default::default()..tabs_snapshot.max_point(), }; wrapper.sync(tabs_snapshot.clone(), vec![edit]);