Generalize pasting when number of selections doesn't match clipboard's

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra
2021-04-14 19:02:44 +02:00
co-authored by Nathan Sobo
parent ce7966d00b
commit f4538e9eb5
3 changed files with 81 additions and 81 deletions
+22
View File
@@ -69,6 +69,28 @@ impl Anchor {
.then_with(|| self_bias.cmp(other_bias)),
})
}
pub fn bias_left(&self, buffer: &Buffer) -> Result<Anchor> {
match self {
Anchor::Start
| Anchor::Middle {
bias: AnchorBias::Left,
..
} => Ok(self.clone()),
_ => buffer.anchor_before(self),
}
}
pub fn bias_right(&self, buffer: &Buffer) -> Result<Anchor> {
match self {
Anchor::End
| Anchor::Middle {
bias: AnchorBias::Right,
..
} => Ok(self.clone()),
_ => buffer.anchor_after(self),
}
}
}
pub trait AnchorRangeExt {
+6
View File
@@ -2264,6 +2264,12 @@ impl ToOffset for Anchor {
}
}
impl<'a> ToOffset for &'a Anchor {
fn to_offset(&self, buffer: &Buffer) -> Result<usize> {
Ok(buffer.summary_for_anchor(self)?.chars)
}
}
pub trait ToPoint {
fn to_point(&self, buffer: &Buffer) -> Result<Point>;
}