Make Clipboard argument in Widget trait mutable

This commit is contained in:
Héctor Ramón Jiménez 2021-03-10 01:59:02 +01:00
parent 35425001ed
commit 21971e0037
31 changed files with 173 additions and 127 deletions

View file

@ -48,6 +48,18 @@ impl Cursor {
}
}
/// Returns the current selection of the [`Cursor`] for the given [`Value`].
///
/// `start` is guaranteed to be <= than `end`.
pub fn selection(&self, value: &Value) -> Option<(usize, usize)> {
match self.state(value) {
State::Selection { start, end } => {
Some((start.min(end), start.max(end)))
}
_ => None,
}
}
pub(crate) fn move_to(&mut self, position: usize) {
self.state = State::Index(position);
}
@ -161,15 +173,6 @@ impl Cursor {
end.min(value.len())
}
pub(crate) fn selection(&self, value: &Value) -> Option<(usize, usize)> {
match self.state(value) {
State::Selection { start, end } => {
Some((start.min(end), start.max(end)))
}
_ => None,
}
}
fn left(&self, value: &Value) -> usize {
match self.state(value) {
State::Index(index) => index,