Reimplement BlockSnapshot::{clip_point,to_block_point,max_point}
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
e60500dd7c
commit
1c3bf90a8a
2 changed files with 152 additions and 105 deletions
|
@ -214,7 +214,6 @@ impl DisplayMapSnapshot {
|
||||||
self.tabs_snapshot
|
self.tabs_snapshot
|
||||||
.to_tab_point(point.to_fold_point(&self.folds_snapshot, bias)),
|
.to_tab_point(point.to_fold_point(&self.folds_snapshot, bias)),
|
||||||
),
|
),
|
||||||
bias,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -513,66 +513,67 @@ impl BlockSnapshot {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn max_point(&self) -> BlockPoint {
|
pub fn max_point(&self) -> BlockPoint {
|
||||||
todo!()
|
self.to_block_point(self.wrap_snapshot.max_point())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clip_point(&self, point: BlockPoint, bias: Bias) -> BlockPoint {
|
pub fn clip_point(&self, point: BlockPoint, bias: Bias) -> BlockPoint {
|
||||||
todo!()
|
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>();
|
||||||
// let mut cursor = self.transforms.cursor::<(BlockPoint, WrapPoint)>();
|
cursor.seek(&BlockRow(point.row), Bias::Right, &());
|
||||||
// cursor.seek(&point, Bias::Right, &());
|
|
||||||
// if let Some(transform) = cursor.prev_item() {
|
let max_input_row = WrapRow(self.transforms.summary().input_rows);
|
||||||
// if transform.is_isomorphic() && point == cursor.start().0 {
|
let search_left =
|
||||||
// return point;
|
(bias == Bias::Left && cursor.start().1 .0 > 0) || cursor.end(&()).1 == max_input_row;
|
||||||
// }
|
|
||||||
// }
|
loop {
|
||||||
// if let Some(transform) = cursor.item() {
|
if let Some(transform) = cursor.item() {
|
||||||
// if transform.is_isomorphic() {
|
if transform.is_isomorphic() {
|
||||||
// let (output_start, input_start) = cursor.start();
|
let (output_start_row, input_start_row) = cursor.start();
|
||||||
// let output_overshoot = point.0 - output_start.0;
|
let (output_end_row, input_end_row) = cursor.end(&());
|
||||||
// let input_point = self
|
|
||||||
// .wrap_snapshot
|
if point.row >= output_end_row.0 {
|
||||||
// .clip_point(WrapPoint(input_start.0 + output_overshoot), bias);
|
return BlockPoint::new(
|
||||||
// let input_overshoot = input_point.0 - input_start.0;
|
output_end_row.0 - 1,
|
||||||
// BlockPoint(output_start.0 + input_overshoot)
|
self.wrap_snapshot.line_len(input_end_row.0 - 1),
|
||||||
// } else {
|
);
|
||||||
// if bias == Bias::Left && cursor.start().1 .0 > Point::zero()
|
}
|
||||||
// || cursor.end(&()).1 == self.wrap_snapshot.max_point()
|
|
||||||
// {
|
let output_start = Point::new(output_start_row.0, 0);
|
||||||
// loop {
|
if point.0 > output_start {
|
||||||
// cursor.prev(&());
|
let output_overshoot = point.0 - output_start;
|
||||||
// let transform = cursor.item().unwrap();
|
let input_start = Point::new(input_start_row.0, 0);
|
||||||
// if transform.is_isomorphic() {
|
let input_point = self
|
||||||
// return BlockPoint(cursor.end(&()).0 .0);
|
.wrap_snapshot
|
||||||
// }
|
.clip_point(WrapPoint(input_start + output_overshoot), bias);
|
||||||
// }
|
let input_overshoot = input_point.0 - input_start;
|
||||||
// } else {
|
return BlockPoint(output_start + input_overshoot);
|
||||||
// loop {
|
} else {
|
||||||
// cursor.next(&());
|
return BlockPoint(output_start);
|
||||||
// let transform = cursor.item().unwrap();
|
}
|
||||||
// if transform.is_isomorphic() {
|
} else if search_left {
|
||||||
// return BlockPoint(cursor.start().0 .0);
|
cursor.prev(&());
|
||||||
// }
|
} else {
|
||||||
// }
|
cursor.next(&());
|
||||||
// }
|
}
|
||||||
// }
|
} else {
|
||||||
// } else {
|
return self.max_point();
|
||||||
// self.max_point()
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_block_point(&self, wrap_point: WrapPoint, bias: Bias) -> BlockPoint {
|
pub fn to_block_point(&self, wrap_point: WrapPoint) -> BlockPoint {
|
||||||
todo!()
|
let mut cursor = self.transforms.cursor::<(WrapRow, BlockRow)>();
|
||||||
// let mut cursor = self.transforms.cursor::<(WrapPoint, BlockPoint)>();
|
cursor.seek(&WrapRow(wrap_point.row()), Bias::Right, &());
|
||||||
// cursor.seek(&wrap_point, bias, &());
|
if let Some(transform) = cursor.item() {
|
||||||
// while let Some(item) = cursor.item() {
|
debug_assert!(transform.is_isomorphic());
|
||||||
// if item.is_isomorphic() {
|
} else {
|
||||||
// break;
|
return self.max_point();
|
||||||
// }
|
}
|
||||||
// cursor.next(&());
|
|
||||||
// }
|
let (input_start_row, output_start_row) = cursor.start();
|
||||||
// let (input_start, output_start) = cursor.start();
|
let input_start = Point::new(input_start_row.0, 0);
|
||||||
// let input_overshoot = wrap_point.0 - input_start.0;
|
let output_start = Point::new(output_start_row.0, 0);
|
||||||
// BlockPoint(output_start.0 + input_overshoot)
|
let input_overshoot = wrap_point.0 - input_start;
|
||||||
|
BlockPoint(output_start + input_overshoot)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_wrap_point(&self, block_point: BlockPoint) -> WrapPoint {
|
pub fn to_wrap_point(&self, block_point: BlockPoint) -> WrapPoint {
|
||||||
|
@ -907,50 +908,76 @@ mod tests {
|
||||||
snapshot.text(),
|
snapshot.text(),
|
||||||
"aaa\nBLOCK 1\nBLOCK 2\nbbb\nccc\nddd\nBLOCK 3"
|
"aaa\nBLOCK 1\nBLOCK 2\nbbb\nccc\nddd\nBLOCK 3"
|
||||||
);
|
);
|
||||||
// assert_eq!(
|
assert_eq!(
|
||||||
// snapshot.to_block_point(WrapPoint::new(1, 0), Bias::Right),
|
snapshot.to_block_point(WrapPoint::new(0, 3)),
|
||||||
// BlockPoint::new(3, 0)
|
BlockPoint::new(0, 3)
|
||||||
// );
|
);
|
||||||
// assert_eq!(
|
assert_eq!(
|
||||||
// snapshot.clip_point(BlockPoint::new(1, 0), Bias::Left),
|
snapshot.to_block_point(WrapPoint::new(1, 0)),
|
||||||
// BlockPoint::new(1, 0)
|
BlockPoint::new(3, 0)
|
||||||
// );
|
);
|
||||||
// assert_eq!(
|
assert_eq!(
|
||||||
// snapshot.clip_point(BlockPoint::new(1, 0), Bias::Right),
|
snapshot.to_block_point(WrapPoint::new(3, 3)),
|
||||||
// BlockPoint::new(1, 0)
|
BlockPoint::new(5, 3)
|
||||||
// );
|
);
|
||||||
// assert_eq!(
|
|
||||||
// snapshot.clip_point(BlockPoint::new(1, 1), Bias::Left),
|
assert_eq!(
|
||||||
// BlockPoint::new(1, 0)
|
snapshot.to_wrap_point(BlockPoint::new(0, 3)),
|
||||||
// );
|
WrapPoint::new(0, 3)
|
||||||
// assert_eq!(
|
);
|
||||||
// snapshot.clip_point(BlockPoint::new(1, 1), Bias::Right),
|
assert_eq!(
|
||||||
// BlockPoint::new(3, 0)
|
snapshot.to_wrap_point(BlockPoint::new(1, 0)),
|
||||||
// );
|
WrapPoint::new(1, 0)
|
||||||
// assert_eq!(
|
);
|
||||||
// snapshot.clip_point(BlockPoint::new(3, 0), Bias::Left),
|
assert_eq!(
|
||||||
// BlockPoint::new(3, 0)
|
snapshot.to_wrap_point(BlockPoint::new(3, 0)),
|
||||||
// );
|
WrapPoint::new(1, 0)
|
||||||
// assert_eq!(
|
);
|
||||||
// snapshot.clip_point(BlockPoint::new(3, 0), Bias::Right),
|
assert_eq!(
|
||||||
// BlockPoint::new(3, 0)
|
snapshot.to_wrap_point(BlockPoint::new(6, 0)),
|
||||||
// );
|
WrapPoint::new(3, 3)
|
||||||
// assert_eq!(
|
);
|
||||||
// snapshot.clip_point(BlockPoint::new(5, 3), Bias::Left),
|
|
||||||
// BlockPoint::new(5, 3)
|
assert_eq!(
|
||||||
// );
|
snapshot.clip_point(BlockPoint::new(1, 0), Bias::Left),
|
||||||
// assert_eq!(
|
BlockPoint::new(0, 3)
|
||||||
// snapshot.clip_point(BlockPoint::new(5, 3), Bias::Right),
|
);
|
||||||
// BlockPoint::new(5, 3)
|
assert_eq!(
|
||||||
// );
|
snapshot.clip_point(BlockPoint::new(1, 0), Bias::Right),
|
||||||
// assert_eq!(
|
BlockPoint::new(3, 0)
|
||||||
// snapshot.clip_point(BlockPoint::new(6, 0), Bias::Left),
|
);
|
||||||
// BlockPoint::new(5, 3)
|
assert_eq!(
|
||||||
// );
|
snapshot.clip_point(BlockPoint::new(1, 1), Bias::Left),
|
||||||
// assert_eq!(
|
BlockPoint::new(0, 3)
|
||||||
// snapshot.clip_point(BlockPoint::new(6, 0), Bias::Right),
|
);
|
||||||
// BlockPoint::new(5, 3)
|
assert_eq!(
|
||||||
// );
|
snapshot.clip_point(BlockPoint::new(1, 1), Bias::Right),
|
||||||
|
BlockPoint::new(3, 0)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
snapshot.clip_point(BlockPoint::new(3, 0), Bias::Left),
|
||||||
|
BlockPoint::new(3, 0)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
snapshot.clip_point(BlockPoint::new(3, 0), Bias::Right),
|
||||||
|
BlockPoint::new(3, 0)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
snapshot.clip_point(BlockPoint::new(5, 3), Bias::Left),
|
||||||
|
BlockPoint::new(5, 3)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
snapshot.clip_point(BlockPoint::new(5, 3), Bias::Right),
|
||||||
|
BlockPoint::new(5, 3)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
snapshot.clip_point(BlockPoint::new(6, 0), Bias::Left),
|
||||||
|
BlockPoint::new(5, 3)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
snapshot.clip_point(BlockPoint::new(6, 0), Bias::Right),
|
||||||
|
BlockPoint::new(5, 3)
|
||||||
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
snapshot.buffer_rows(0).collect::<Vec<_>>(),
|
snapshot.buffer_rows(0).collect::<Vec<_>>(),
|
||||||
|
@ -1227,15 +1254,36 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(blocks_snapshot.text(), expected_text);
|
assert_eq!(blocks_snapshot.text(), expected_text);
|
||||||
// for row in 0..=blocks_snapshot.wrap_snapshot.max_point().row() {
|
for row in 0..=blocks_snapshot.wrap_snapshot.max_point().row() {
|
||||||
// let wrap_point = WrapPoint::new(row, 0);
|
let wrap_point = WrapPoint::new(row, 0);
|
||||||
// let block_point = blocks_snapshot.to_block_point(wrap_point, Bias::Right);
|
let block_point = blocks_snapshot.to_block_point(wrap_point);
|
||||||
// assert_eq!(blocks_snapshot.to_wrap_point(block_point), wrap_point);
|
assert_eq!(blocks_snapshot.to_wrap_point(block_point), wrap_point);
|
||||||
// }
|
}
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
blocks_snapshot.buffer_rows(0).collect::<Vec<_>>(),
|
blocks_snapshot.buffer_rows(0).collect::<Vec<_>>(),
|
||||||
expected_buffer_rows
|
expected_buffer_rows
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut block_point = BlockPoint::new(0, 0);
|
||||||
|
for c in expected_text.chars() {
|
||||||
|
let left_point = blocks_snapshot.clip_point(block_point, Bias::Left);
|
||||||
|
let right_point = blocks_snapshot.clip_point(block_point, Bias::Right);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
blocks_snapshot.to_block_point(blocks_snapshot.to_wrap_point(left_point)),
|
||||||
|
left_point
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
blocks_snapshot.to_block_point(blocks_snapshot.to_wrap_point(right_point)),
|
||||||
|
right_point
|
||||||
|
);
|
||||||
|
|
||||||
|
if c == '\n' {
|
||||||
|
block_point.0 += Point::new(1, 0);
|
||||||
|
} else {
|
||||||
|
block_point.column += c.len_utf8() as u32;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue