Generalize pasting when number of selections doesn't match clipboard's
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
co-authored by
Nathan Sobo
parent
ce7966d00b
commit
f4538e9eb5
@@ -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 {
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user