This commit is contained in:
Nathan Sobo
2021-07-19 13:59:07 -06:00
parent 5a33612f0f
commit e193a660aa
5 changed files with 39 additions and 15 deletions
+2 -1
View File
@@ -25,7 +25,8 @@ pub mod json;
pub mod keymap; pub mod keymap;
mod platform; mod platform;
pub use gpui_macros::test; 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::{ pub use presenter::{
AfterLayoutContext, Axis, DebugContext, EventContext, LayoutContext, PaintContext, AfterLayoutContext, Axis, DebugContext, EventContext, LayoutContext, PaintContext,
SizeConstraint, Vector2FExt, SizeConstraint, Vector2FExt,
+6
View File
@@ -72,6 +72,12 @@ impl Sub for Point {
impl<'a> AddAssign<&'a Self> for Point { impl<'a> AddAssign<&'a Self> for Point {
fn add_assign(&mut self, other: &'a Self) { 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 { if other.row == 0 {
self.column += other.column; self.column += other.column;
} else { } else {
+1 -1
View File
@@ -19,7 +19,7 @@ use std::{
}; };
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)] #[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
pub struct OutputPoint(super::Point); pub struct OutputPoint(pub super::Point);
impl OutputPoint { impl OutputPoint {
pub fn new(row: u32, column: u32) -> Self { pub fn new(row: u32, column: u32) -> Self {
+17 -3
View File
@@ -4,7 +4,7 @@ use super::fold_map::{
Chunks as InputChunks, Edit as InputEdit, HighlightedChunks as InputHighlightedChunks, Chunks as InputChunks, Edit as InputEdit, HighlightedChunks as InputHighlightedChunks,
OutputOffset as InputOffset, OutputPoint as InputPoint, Snapshot as InputSnapshot, 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::{ use std::{
mem, mem,
ops::{AddAssign, Range}, ops::{AddAssign, Range},
@@ -232,7 +232,7 @@ impl Snapshot {
pub struct OutputOffset(pub usize); pub struct OutputOffset(pub usize);
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)] #[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
pub struct OutputPoint(super::Point); pub struct OutputPoint(pub super::Point);
impl OutputPoint { impl OutputPoint {
pub fn new(row: u32, column: u32) -> Self { pub fn new(row: u32, column: u32) -> Self {
@@ -262,7 +262,7 @@ impl OutputPoint {
impl AddAssign<Self> for OutputPoint { impl AddAssign<Self> for OutputPoint {
fn add_assign(&mut self, rhs: Self) { 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, 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 { impl<'a> std::ops::AddAssign<&'a Self> for TextSummary {
fn add_assign(&mut self, other: &'a Self) { fn add_assign(&mut self, other: &'a Self) {
let joined_chars = self.last_line_chars + other.first_line_chars; let joined_chars = self.last_line_chars + other.first_line_chars;
+13 -10
View File
@@ -1,6 +1,5 @@
use super::tab_map::{ use super::tab_map::{
Edit as InputEdit, OutputOffset as InputOffset, OutputPoint as InputPoint, Edit as InputEdit, OutputPoint as InputPoint, Snapshot as InputSnapshot, TextSummary,
Snapshot as InputSnapshot, TextSummary,
}; };
use crate::{ use crate::{
editor::Point, editor::Point,
@@ -200,11 +199,11 @@ impl BackgroundWrapper {
&(), &(),
); );
for edit in edits { while let Some(edit) = edits.next() {
if edit.new_rows.start > new_transforms.summary().input.row() { if edit.new_rows.start > new_transforms.summary().input.lines.row {
new_transforms.push( new_transforms.push(
Transform::isomorphic(new_snapshot.input.text_summary_for_rows( Transform::isomorphic(new_snapshot.text_summary_for_rows(
new_transforms.summary().input.row()..edit.new_rows.start, 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 let Some(next_edit) = edits.peek() {
if next_edit.old_rows.start > old_cursor.seek_end(&()).row() { if next_edit.old_rows.start > old_cursor.seek_end(&()).row() {
new_transforms.push( new_transforms.push(
@@ -249,7 +248,11 @@ impl BackgroundWrapper {
); );
old_cursor.next(&()); old_cursor.next(&());
new_transforms.push_tree( 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 { impl<'a> sum_tree::Dimension<'a, TransformSummary> for InputPoint {
fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) { 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(), font_system.clone(),
); );
let edit = InputEdit { 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(), new_lines: Default::default()..tabs_snapshot.max_point(),
}; };
wrapper.sync(tabs_snapshot.clone(), vec![edit]); wrapper.sync(tabs_snapshot.clone(), vec![edit]);