pub struct Selection {
pub begin: Place,
pub end: Place,
}Expand description
A selection: an anchor and an active end, in that order, unordered by value.
use pdfrum_form::edit::{Place, Selection};
let lo = Place::new(0, 0, Some(1));
let hi = Place::new(0, 0, Some(5));
let forwards = Selection::new(lo, hi);
let backwards = Selection::new(hi, lo);
// The direction is kept, so the two are not equal.
assert!(!forwards.is_backwards());
assert!(backwards.is_backwards());
assert_ne!(forwards, backwards);
// They still cover the same text.
assert_eq!(forwards.range(), backwards.range());Fields§
§begin: PlaceThe fixed end.
end: PlaceThe end that moves with the caret.
Implementations§
Source§impl Selection
impl Selection
Sourcepub fn empty() -> Selection
pub fn empty() -> Selection
A collapsed selection at the start of the text.
use pdfrum_form::edit::{Place, PlaceExt, Selection};
assert!(Selection::empty().is_empty());
assert_eq!(Selection::empty().begin, Place::start());
// An anchor at the start is still an anchor, so this is no reset.
assert!(!Selection::empty().is_reset());Sourcepub fn new(begin: Place, end: Place) -> Selection
pub fn new(begin: Place, end: Place) -> Selection
A selection anchored at begin, active at end.
use pdfrum_form::edit::{Place, Selection};
let sel = Selection::new(Place::new(0, 0, Some(7)), Place::new(0, 0, Some(2)));
// Nothing orders the two on the way in: this one runs backwards.
assert!(sel.is_backwards());
assert_eq!(sel.range().begin(), Place::new(0, 0, Some(2)));Sourcepub fn collapsed_at(place: Place) -> Selection
pub fn collapsed_at(place: Place) -> Selection
A live anchor at one place, selecting nothing.
What a mutation or a mouse-down leaves behind, and what a following shift-move extends from.
use pdfrum_form::edit::{Place, Selection};
let here = Place::new(0, 0, Some(3));
let sel = Selection::collapsed_at(here);
assert!(sel.is_empty());
assert!(!sel.is_reset(), "the anchor is live");
assert_eq!(sel.begin, here);Sourcepub fn reset() -> Selection
pub fn reset() -> Selection
No selection and no anchor.
Distinct from a collapsed selection: a shift-move from here anchors on the caret’s previous position rather than on this one.
use pdfrum_form::edit::{Place, Selection};
assert!(Selection::reset().is_reset());
assert_ne!(
Selection::reset(),
Selection::collapsed_at(Place::new(0, 0, Some(3)))
);Sourcepub fn is_empty(self) -> bool
pub fn is_empty(self) -> bool
Whether the selection covers no text.
Says nothing about whether an anchor exists; see
Selection::is_reset.
use pdfrum_form::edit::{Place, Selection};
let here = Place::new(0, 0, Some(3));
assert!(Selection::collapsed_at(here).is_empty());
assert!(!Selection::new(here, Place::new(0, 0, Some(5))).is_empty());Sourcepub fn is_reset(self) -> bool
pub fn is_reset(self) -> bool
Whether the selection has no anchor at all.
use pdfrum_form::edit::{Place, Selection};
assert!(Selection::reset().is_reset());
assert!(!Selection::collapsed_at(Place::new(0, 0, Some(3))).is_reset());Sourcepub fn is_backwards(self) -> bool
pub fn is_backwards(self) -> bool
Whether the active end lies before the anchor.
use pdfrum_form::edit::{Place, Selection};
let lo = Place::new(0, 0, Some(1));
let hi = Place::new(0, 0, Some(5));
assert!(Selection::new(hi, lo).is_backwards());
assert!(!Selection::new(lo, hi).is_backwards());Sourcepub fn range(self) -> Range
pub fn range(self) -> Range
The span, ordered. Direction is discarded here and nowhere else.
use pdfrum_form::edit::{Place, Selection};
let sel = Selection::new(Place::new(0, 0, Some(7)), Place::new(0, 0, Some(2)));
assert!(sel.range().begin() <= sel.range().end());
assert_eq!(sel.range().begin(), Place::new(0, 0, Some(2)));Sourcepub fn set_active(&mut self, place: Place)
pub fn set_active(&mut self, place: Place)
Moves the active end, keeping the anchor. What a shift-move does once an anchor exists.
use pdfrum_form::edit::{Place, Selection};
let anchor = Place::new(0, 0, Some(1));
let mut sel = Selection::collapsed_at(anchor);
sel.set_active(Place::new(0, 0, Some(4)));
assert_eq!(sel.begin, anchor, "the anchor stays put");
assert_eq!(sel.end, Place::new(0, 0, Some(4)));
assert!(!sel.is_empty());Trait Implementations§
impl Copy for Selection
impl Eq for Selection
impl StructuralPartialEq for Selection
Auto Trait Implementations§
impl Freeze for Selection
impl RefUnwindSafe for Selection
impl Send for Selection
impl Sync for Selection
impl Unpin for Selection
impl UnsafeUnpin for Selection
impl UnwindSafe for Selection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.