Fix WrapMap::clip_point at the end of a soft-wrapped line
If that's the case and `Bias` is `Left` we clip to the last character of the soft-wrapped line. Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
co-authored by
Nathan Sobo
parent
915c710f94
commit
ef42d14b8c
@@ -369,6 +369,14 @@ mod tests {
|
||||
.collect::<String>(),
|
||||
" two \nthree four \nfive\nsix seven \neight"
|
||||
);
|
||||
assert_eq!(
|
||||
snapshot.clip_point(DisplayPoint::new(0, 8), Bias::Left),
|
||||
DisplayPoint::new(0, 7)
|
||||
);
|
||||
assert_eq!(
|
||||
snapshot.clip_point(DisplayPoint::new(0, 8), Bias::Right),
|
||||
DisplayPoint::new(1, 0)
|
||||
);
|
||||
|
||||
buffer.update(&mut cx, |buffer, cx| {
|
||||
let ix = buffer.text().find("seven").unwrap();
|
||||
|
||||
@@ -208,7 +208,16 @@ impl Snapshot {
|
||||
OutputPoint(cursor.sum_start().0 + (point.0 - cursor.seek_start().0))
|
||||
}
|
||||
|
||||
pub fn clip_point(&self, point: OutputPoint, bias: Bias) -> OutputPoint {
|
||||
pub fn clip_point(&self, mut point: OutputPoint, bias: Bias) -> OutputPoint {
|
||||
if bias == Bias::Left {
|
||||
let mut cursor = self.transforms.cursor::<OutputPoint, ()>();
|
||||
cursor.seek(&point, Bias::Right, &());
|
||||
let transform = cursor.item().expect("invalid point");
|
||||
if !transform.is_isomorphic() {
|
||||
*point.column_mut() -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
self.to_output_point(self.input.clip_point(self.to_input_point(point), bias))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user