Use a single Bias enum everywhere
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
use super::{
|
||||
buffer::{AnchorRangeExt, TextSummary},
|
||||
Anchor, Bias, Buffer, DisplayPoint, Edit, Point, ToOffset,
|
||||
Anchor, Buffer, DisplayPoint, Edit, Point, ToOffset,
|
||||
};
|
||||
use crate::{
|
||||
editor::buffer,
|
||||
settings::StyleId,
|
||||
sum_tree::{self, Cursor, FilterCursor, SeekBias, SumTree},
|
||||
sum_tree::{self, Cursor, FilterCursor, SumTree},
|
||||
time,
|
||||
util::Bias,
|
||||
};
|
||||
use gpui::{AppContext, ModelHandle};
|
||||
use parking_lot::{Mutex, MutexGuard};
|
||||
@@ -125,7 +126,7 @@ impl FoldMap {
|
||||
let mut new_tree = SumTree::new();
|
||||
let mut cursor = self.folds.cursor::<_, ()>();
|
||||
for fold in folds {
|
||||
new_tree.push_tree(cursor.slice(&fold, SeekBias::Right, buffer), buffer);
|
||||
new_tree.push_tree(cursor.slice(&fold, Bias::Right, buffer), buffer);
|
||||
new_tree.push(fold, buffer);
|
||||
}
|
||||
new_tree.push_tree(cursor.suffix(buffer), buffer);
|
||||
@@ -173,7 +174,7 @@ impl FoldMap {
|
||||
let mut cursor = self.folds.cursor::<_, ()>();
|
||||
let mut folds = SumTree::new();
|
||||
for fold_ix in fold_ixs_to_delete {
|
||||
folds.push_tree(cursor.slice(&fold_ix, SeekBias::Right, buffer), buffer);
|
||||
folds.push_tree(cursor.slice(&fold_ix, Bias::Right, buffer), buffer);
|
||||
cursor.next(buffer);
|
||||
}
|
||||
folds.push_tree(cursor.suffix(buffer), buffer);
|
||||
@@ -210,14 +211,14 @@ impl FoldMap {
|
||||
let offset = offset.to_offset(buffer);
|
||||
let transforms = self.sync(cx);
|
||||
let mut cursor = transforms.cursor::<usize, usize>();
|
||||
cursor.seek(&offset, SeekBias::Right, &());
|
||||
cursor.seek(&offset, Bias::Right, &());
|
||||
cursor.item().map_or(false, |t| t.display_text.is_some())
|
||||
}
|
||||
|
||||
pub fn is_line_folded(&self, display_row: u32, cx: &AppContext) -> bool {
|
||||
let transforms = self.sync(cx);
|
||||
let mut cursor = transforms.cursor::<DisplayPoint, DisplayPoint>();
|
||||
cursor.seek(&DisplayPoint::new(display_row, 0), SeekBias::Right, &());
|
||||
cursor.seek(&DisplayPoint::new(display_row, 0), Bias::Right, &());
|
||||
while let Some(transform) = cursor.item() {
|
||||
if transform.display_text.is_some() {
|
||||
return true;
|
||||
@@ -242,7 +243,7 @@ impl FoldMap {
|
||||
pub fn to_buffer_point(&self, display_point: DisplayPoint, cx: &AppContext) -> Point {
|
||||
let transforms = self.sync(cx);
|
||||
let mut cursor = transforms.cursor::<DisplayPoint, TransformSummary>();
|
||||
cursor.seek(&display_point, SeekBias::Right, &());
|
||||
cursor.seek(&display_point, Bias::Right, &());
|
||||
let overshoot = display_point.0 - cursor.start().display.lines;
|
||||
cursor.start().buffer.lines + overshoot
|
||||
}
|
||||
@@ -250,7 +251,7 @@ impl FoldMap {
|
||||
pub fn to_display_point(&self, point: Point, cx: &AppContext) -> DisplayPoint {
|
||||
let transforms = self.sync(cx);
|
||||
let mut cursor = transforms.cursor::<Point, TransformSummary>();
|
||||
cursor.seek(&point, SeekBias::Right, &());
|
||||
cursor.seek(&point, Bias::Right, &());
|
||||
let overshoot = point - cursor.start().buffer.lines;
|
||||
DisplayPoint(cmp::min(
|
||||
cursor.start().display.lines + overshoot,
|
||||
@@ -275,17 +276,14 @@ impl FoldMap {
|
||||
let mut new_transforms = SumTree::new();
|
||||
let mut transforms = self.transforms.lock();
|
||||
let mut cursor = transforms.cursor::<usize, usize>();
|
||||
cursor.seek(&0, SeekBias::Right, &());
|
||||
cursor.seek(&0, Bias::Right, &());
|
||||
|
||||
while let Some(mut edit) = edits.next() {
|
||||
new_transforms.push_tree(
|
||||
cursor.slice(&edit.old_range.start, SeekBias::Left, &()),
|
||||
&(),
|
||||
);
|
||||
new_transforms.push_tree(cursor.slice(&edit.old_range.start, Bias::Left, &()), &());
|
||||
edit.new_range.start -= edit.old_range.start - cursor.start();
|
||||
edit.old_range.start = *cursor.start();
|
||||
|
||||
cursor.seek(&edit.old_range.end, SeekBias::Right, &());
|
||||
cursor.seek(&edit.old_range.end, Bias::Right, &());
|
||||
cursor.next(&());
|
||||
|
||||
let mut delta = edit.delta();
|
||||
@@ -302,7 +300,7 @@ impl FoldMap {
|
||||
|
||||
if next_edit.old_range.end >= edit.old_range.end {
|
||||
edit.old_range.end = next_edit.old_range.end;
|
||||
cursor.seek(&edit.old_range.end, SeekBias::Right, &());
|
||||
cursor.seek(&edit.old_range.end, Bias::Right, &());
|
||||
cursor.next(&());
|
||||
}
|
||||
} else {
|
||||
@@ -315,7 +313,7 @@ impl FoldMap {
|
||||
|
||||
let anchor = buffer.anchor_before(edit.new_range.start);
|
||||
let mut folds_cursor = self.folds.cursor::<_, ()>();
|
||||
folds_cursor.seek(&Fold(anchor..Anchor::End), SeekBias::Left, buffer);
|
||||
folds_cursor.seek(&Fold(anchor..Anchor::End), Bias::Left, buffer);
|
||||
let mut folds = iter::from_fn(move || {
|
||||
let item = folds_cursor
|
||||
.item()
|
||||
@@ -432,7 +430,7 @@ impl FoldMapSnapshot {
|
||||
|
||||
let display_point = Point::new(start_row, 0);
|
||||
let mut cursor = self.transforms.cursor();
|
||||
cursor.seek(&DisplayPoint(display_point), SeekBias::Left, &());
|
||||
cursor.seek(&DisplayPoint(display_point), Bias::Left, &());
|
||||
|
||||
BufferRows {
|
||||
display_point,
|
||||
@@ -446,7 +444,7 @@ impl FoldMapSnapshot {
|
||||
|
||||
pub fn chunks_at(&self, offset: DisplayOffset) -> Chunks {
|
||||
let mut transform_cursor = self.transforms.cursor::<DisplayOffset, TransformSummary>();
|
||||
transform_cursor.seek(&offset, SeekBias::Right, &());
|
||||
transform_cursor.seek(&offset, Bias::Right, &());
|
||||
let overshoot = offset.0 - transform_cursor.start().display.bytes;
|
||||
let buffer_offset = transform_cursor.start().buffer.bytes + overshoot;
|
||||
Chunks {
|
||||
@@ -459,11 +457,11 @@ impl FoldMapSnapshot {
|
||||
pub fn highlighted_chunks(&mut self, range: Range<DisplayOffset>) -> HighlightedChunks {
|
||||
let mut transform_cursor = self.transforms.cursor::<DisplayOffset, TransformSummary>();
|
||||
|
||||
transform_cursor.seek(&range.end, SeekBias::Right, &());
|
||||
transform_cursor.seek(&range.end, Bias::Right, &());
|
||||
let overshoot = range.end.0 - transform_cursor.start().display.bytes;
|
||||
let buffer_end = transform_cursor.start().buffer.bytes + overshoot;
|
||||
|
||||
transform_cursor.seek(&range.start, SeekBias::Right, &());
|
||||
transform_cursor.seek(&range.start, Bias::Right, &());
|
||||
let overshoot = range.start.0 - transform_cursor.start().display.bytes;
|
||||
let buffer_start = transform_cursor.start().buffer.bytes + overshoot;
|
||||
|
||||
@@ -484,7 +482,7 @@ impl FoldMapSnapshot {
|
||||
|
||||
pub fn to_display_offset(&self, point: DisplayPoint) -> DisplayOffset {
|
||||
let mut cursor = self.transforms.cursor::<DisplayPoint, TransformSummary>();
|
||||
cursor.seek(&point, SeekBias::Right, &());
|
||||
cursor.seek(&point, Bias::Right, &());
|
||||
let overshoot = point.0 - cursor.start().display.lines;
|
||||
let mut offset = cursor.start().display.bytes;
|
||||
if !overshoot.is_zero() {
|
||||
@@ -500,7 +498,7 @@ impl FoldMapSnapshot {
|
||||
|
||||
pub fn to_buffer_offset(&self, point: DisplayPoint) -> usize {
|
||||
let mut cursor = self.transforms.cursor::<DisplayPoint, TransformSummary>();
|
||||
cursor.seek(&point, SeekBias::Right, &());
|
||||
cursor.seek(&point, Bias::Right, &());
|
||||
let overshoot = point.0 - cursor.start().display.lines;
|
||||
self.buffer
|
||||
.to_offset(cursor.start().buffer.lines + overshoot)
|
||||
@@ -509,7 +507,7 @@ impl FoldMapSnapshot {
|
||||
#[cfg(test)]
|
||||
pub fn clip_offset(&self, offset: DisplayOffset, bias: Bias) -> DisplayOffset {
|
||||
let mut cursor = self.transforms.cursor::<DisplayOffset, TransformSummary>();
|
||||
cursor.seek(&offset, SeekBias::Right, &());
|
||||
cursor.seek(&offset, Bias::Right, &());
|
||||
if let Some(transform) = cursor.item() {
|
||||
let transform_start = cursor.start().display.bytes;
|
||||
if transform.display_text.is_some() {
|
||||
@@ -534,7 +532,7 @@ impl FoldMapSnapshot {
|
||||
|
||||
pub fn clip_point(&self, point: DisplayPoint, bias: Bias) -> DisplayPoint {
|
||||
let mut cursor = self.transforms.cursor::<DisplayPoint, TransformSummary>();
|
||||
cursor.seek(&point, SeekBias::Right, &());
|
||||
cursor.seek(&point, Bias::Right, &());
|
||||
if let Some(transform) = cursor.item() {
|
||||
let transform_start = cursor.start().display.lines;
|
||||
if transform.display_text.is_some() {
|
||||
|
||||
Reference in New Issue
Block a user