Merge branch 'main' into select-on-rename

This commit is contained in:
Nathan Sobo
2022-03-11 15:30:07 -07:00
28 changed files with 1063 additions and 257 deletions
+22 -31
View File
@@ -1,3 +1,4 @@
use super::TextHighlights;
use crate::{
multi_buffer::MultiBufferRows, Anchor, AnchorRangeExt, MultiBufferChunks, MultiBufferSnapshot,
ToOffset,
@@ -16,12 +17,6 @@ use std::{
};
use sum_tree::{Bias, Cursor, FilterCursor, SumTree};
use super::TextHighlights;
pub trait ToFoldPoint {
fn to_fold_point(&self, snapshot: &FoldSnapshot, bias: Bias) -> FoldPoint;
}
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
pub struct FoldPoint(pub super::Point);
@@ -81,26 +76,6 @@ impl FoldPoint {
}
}
impl ToFoldPoint for Point {
fn to_fold_point(&self, snapshot: &FoldSnapshot, bias: Bias) -> 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.start().0 {
cursor.start().1
} else {
cursor.end(&()).1
}
} else {
let overshoot = *self - cursor.start().0;
FoldPoint(cmp::min(
cursor.start().1 .0 + overshoot,
cursor.end(&()).1 .0,
))
}
}
}
impl<'a> sum_tree::Dimension<'a, TransformSummary> for FoldPoint {
fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) {
self.0 += &summary.output.lines;
@@ -566,6 +541,24 @@ impl FoldSnapshot {
summary
}
pub fn to_fold_point(&self, point: Point, bias: Bias) -> FoldPoint {
let mut cursor = self.transforms.cursor::<(Point, FoldPoint)>();
cursor.seek(&point, Bias::Right, &());
if cursor.item().map_or(false, |t| t.is_fold()) {
if bias == Bias::Left || point == cursor.start().0 {
cursor.start().1
} else {
cursor.end(&()).1
}
} else {
let overshoot = point - cursor.start().0;
FoldPoint(cmp::min(
cursor.start().1 .0 + overshoot,
cursor.end(&()).1 .0,
))
}
}
pub fn len(&self) -> FoldOffset {
FoldOffset(self.transforms.summary().output.bytes)
}
@@ -1511,7 +1504,7 @@ mod tests {
let buffer_point = fold_point.to_buffer_point(&snapshot);
let buffer_offset = buffer_point.to_offset(&buffer_snapshot);
assert_eq!(
buffer_point.to_fold_point(&snapshot, Right),
snapshot.to_fold_point(buffer_point, Right),
fold_point,
"{:?} -> fold point",
buffer_point,
@@ -1583,10 +1576,8 @@ mod tests {
}
for fold_range in map.merged_fold_ranges() {
let fold_point = fold_range
.start
.to_point(&buffer_snapshot)
.to_fold_point(&snapshot, Right);
let fold_point =
snapshot.to_fold_point(fold_range.start.to_point(&buffer_snapshot), Right);
assert!(snapshot.is_line_folded(fold_point.row()));
}
+5 -5
View File
@@ -1,5 +1,5 @@
use super::{
fold_map::{self, FoldEdit, FoldPoint, FoldSnapshot, ToFoldPoint},
fold_map::{self, FoldEdit, FoldPoint, FoldSnapshot},
TextHighlights,
};
use crate::MultiBufferSnapshot;
@@ -212,10 +212,6 @@ impl TabSnapshot {
TabPoint::new(input.row(), expanded as u32)
}
pub fn from_point(&self, point: Point, bias: Bias) -> TabPoint {
self.to_tab_point(point.to_fold_point(&self.fold_snapshot, bias))
}
pub fn to_fold_point(&self, output: TabPoint, bias: Bias) -> (FoldPoint, usize, usize) {
let chars = self.fold_snapshot.chars_at(FoldPoint::new(output.row(), 0));
let expanded = output.column() as usize;
@@ -228,6 +224,10 @@ impl TabSnapshot {
)
}
pub fn from_point(&self, point: Point, bias: Bias) -> TabPoint {
self.to_tab_point(self.fold_snapshot.to_fold_point(point, bias))
}
pub fn to_point(&self, point: TabPoint, bias: Bias) -> Point {
self.to_fold_point(point, bias)
.0