Detailed changes
@@ -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,
@@ -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<Self> for Point {
+ fn add_assign(&mut self, other: Self) {
if other.row == 0 {
self.column += other.column;
} else {
@@ -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 {
@@ -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<Self> 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;
@@ -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]);