pub struct TextSelection {
pub base_offset: i32,
pub extent_offset: i32,
pub affinity: TextAffinity,
pub is_directional: bool,
}Expand description
Fields§
§base_offset: i32The offset at which the selection originates.
Might be larger than, smaller than, or equal to extent.
extent_offset: i32The offset at which the selection terminates.
When the user uses the arrow keys to adjust the selection, this is the value that changes. Similarly, if the current theme paints a caret on one side of the selection, this is the location at which to paint the caret.
Might be larger than, smaller than, or equal to base.
affinity: TextAffinityIf the text range is collapsed and has more than one visual location (e.g., occurs at a line break), which of the two locations to use when painting the caret.
is_directional: boolWhether this selection has disambiguated its base and extent.
On some platforms, the base and extent are not disambiguated until the first time the user adjusts the selection. At that point, either the start or the end of the selection becomes the base and the other one becomes the extent and is adjusted.
Implementations§
Source§impl TextSelection
impl TextSelection
Sourcepub const fn new(base_offset: i32, extent_offset: i32) -> TextSelection
pub const fn new(base_offset: i32, extent_offset: i32) -> TextSelection
Creates a text selection.
Sourcepub const fn collapsed(offset: i32, affinity: TextAffinity) -> TextSelection
pub const fn collapsed(offset: i32, affinity: TextAffinity) -> TextSelection
Creates a collapsed selection at the given offset.
A collapsed selection starts and ends at the same offset, which means it contains zero characters but instead serves as an insertion point in the text.
Sourcepub const fn from_position(position: TextPosition) -> TextSelection
pub const fn from_position(position: TextPosition) -> TextSelection
Creates a collapsed selection at the given text position.
A collapsed selection starts and ends at the same offset, which means it contains zero characters but instead serves as an insertion point in the text.
Sourcepub fn range(&self) -> TextRange
pub fn range(&self) -> TextRange
The normalized range this selection covers (Dart’s TextRange superclass).
Sourcepub fn is_collapsed(&self) -> bool
pub fn is_collapsed(&self) -> bool
Whether this range is empty (but still potentially placed inside the text).
Sourcepub fn is_normalized(&self) -> bool
pub fn is_normalized(&self) -> bool
Whether the start of this range precedes the end.
Sourcepub fn base(&self) -> TextPosition
pub fn base(&self) -> TextPosition
The position at which the selection originates.
The TextAffinity of the resulting TextPosition is based on the relative logical
position in the text to the other selection endpoint:
- if
base_offset<extent_offset,basewill have aTextAffinity::Downstreamaffinity; - if
base_offset>extent_offset,basewill have aTextAffinity::Upstreamaffinity; - if the selection is collapsed, the affinity is
affinity.
Sourcepub fn extent(&self) -> TextPosition
pub fn extent(&self) -> TextPosition
The position at which the selection terminates.
When the user uses the arrow keys to adjust the selection, this is the value that changes. Similarly, if the current theme paints a caret on one side of the selection, this is the location at which to paint the caret.
Sourcepub fn copy_with(&self) -> TextSelection
pub fn copy_with(&self) -> TextSelection
Creates a new TextSelection based on the current selection, with the provided
parameters overridden. Dart’s copyWith named arguments are the fluent setters that
follow.
Sourcepub fn base_offset(self, base_offset: i32) -> TextSelection
pub fn base_offset(self, base_offset: i32) -> TextSelection
Dart copyWith(baseOffset:).
Sourcepub fn extent_offset(self, extent_offset: i32) -> TextSelection
pub fn extent_offset(self, extent_offset: i32) -> TextSelection
Dart copyWith(extentOffset:).
Sourcepub fn affinity(self, affinity: TextAffinity) -> TextSelection
pub fn affinity(self, affinity: TextAffinity) -> TextSelection
Dart copyWith(affinity:).
Sourcepub fn is_directional(self, is_directional: bool) -> TextSelection
pub fn is_directional(self, is_directional: bool) -> TextSelection
Dart copyWith(isDirectional:).
Sourcepub fn expand_to(
&self,
position: TextPosition,
extent_at_index: bool,
) -> TextSelection
pub fn expand_to( &self, position: TextPosition, extent_at_index: bool, ) -> TextSelection
Returns the smallest TextSelection that this could expand to in order to include
the given TextPosition.
If the given TextPosition is already inside of the selection, then returns self
without change.
The returned selection will always be a strict superset of the current selection. In
other words, the selection grows to include the given TextPosition.
If extent_at_index is set to true, then the extent will be
placed at the given index regardless of the original order of it and the
base. Otherwise, the base and extent are ordered so as to keep the
original selection’s direction.
Sourcepub fn extend_to(&self, position: TextPosition) -> TextSelection
pub fn extend_to(&self, position: TextPosition) -> TextSelection
Keeping the selection’s base fixed, pivot the
extent to the given TextPosition.
In some cases, the base and extent can be flipped
during this operation, or the size of the selection can be reduced.
Trait Implementations§
Source§impl Clone for TextSelection
impl Clone for TextSelection
impl Copy for TextSelection
Source§impl Debug for TextSelection
impl Debug for TextSelection
Source§impl Display for TextSelection
impl Display for TextSelection
impl Eq for TextSelection
Source§impl From<TextSelection> for TextRange
impl From<TextSelection> for TextRange
Source§fn from(selection: TextSelection) -> TextRange
fn from(selection: TextSelection) -> TextRange
Source§impl Hash for TextSelection
impl Hash for TextSelection
Auto Trait Implementations§
impl Freeze for TextSelection
impl RefUnwindSafe for TextSelection
impl Send for TextSelection
impl Sync for TextSelection
impl Unpin for TextSelection
impl UnsafeUnpin for TextSelection
impl UnwindSafe for TextSelection
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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§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.