mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-25 01:34:02 +00:00
Fix minor bug in BlockMap::clip_point
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
7d1ba6455b
commit
76ee44748e
1 changed files with 45 additions and 0 deletions
|
@ -452,6 +452,11 @@ impl BlockSnapshot {
|
|||
pub fn clip_point(&self, point: BlockPoint, bias: Bias) -> BlockPoint {
|
||||
let mut cursor = self.transforms.cursor::<(BlockPoint, WrapPoint)>();
|
||||
cursor.seek(&point, Bias::Right, &());
|
||||
if let Some(transform) = cursor.prev_item() {
|
||||
if transform.is_isomorphic() && point == cursor.start().0 {
|
||||
return point;
|
||||
}
|
||||
}
|
||||
if let Some(transform) = cursor.item() {
|
||||
if transform.is_isomorphic() {
|
||||
let (output_start, input_start) = cursor.start();
|
||||
|
@ -771,6 +776,46 @@ mod tests {
|
|||
snapshot.to_block_point(WrapPoint::new(1, 0)),
|
||||
BlockPoint::new(3, 0)
|
||||
);
|
||||
assert_eq!(
|
||||
snapshot.clip_point(BlockPoint::new(1, 0), Bias::Left),
|
||||
BlockPoint::new(1, 0)
|
||||
);
|
||||
assert_eq!(
|
||||
snapshot.clip_point(BlockPoint::new(1, 0), Bias::Right),
|
||||
BlockPoint::new(1, 0)
|
||||
);
|
||||
assert_eq!(
|
||||
snapshot.clip_point(BlockPoint::new(1, 1), Bias::Left),
|
||||
BlockPoint::new(1, 0)
|
||||
);
|
||||
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)
|
||||
);
|
||||
|
||||
// Insert a line break, separating two block decorations into separate
|
||||
// lines.
|
||||
|
|
Loading…
Reference in a new issue