Skip to main content

TextSelection

Struct TextSelection 

Source
pub struct TextSelection {
    pub base_offset: i32,
    pub extent_offset: i32,
    pub affinity: TextAffinity,
    pub is_directional: bool,
}
Expand description

A range of text that represents a selection.

Dart’s TextSelection extends TextRange: the range is range, and start / end are the normalized bounds.

Fields§

§base_offset: i32

The offset at which the selection originates.

Might be larger than, smaller than, or equal to extent.

§extent_offset: i32

The 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: TextAffinity

If 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: bool

Whether 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

Source

pub const fn new(base_offset: i32, extent_offset: i32) -> TextSelection

Creates a text selection.

Source

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.

Source

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.

Source

pub fn range(&self) -> TextRange

The normalized range this selection covers (Dart’s TextRange superclass).

Source

pub fn start(&self) -> i32

The index of the first character in the range.

Source

pub fn end(&self) -> i32

The next index after the characters in this range.

Source

pub fn is_valid(&self) -> bool

Whether this range represents a valid position in the text.

Source

pub fn is_collapsed(&self) -> bool

Whether this range is empty (but still potentially placed inside the text).

Source

pub fn is_normalized(&self) -> bool

Whether the start of this range precedes the end.

Source

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:

Source

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.

Source

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.

Source

pub fn base_offset(self, base_offset: i32) -> TextSelection

Dart copyWith(baseOffset:).

Source

pub fn extent_offset(self, extent_offset: i32) -> TextSelection

Dart copyWith(extentOffset:).

Source

pub fn affinity(self, affinity: TextAffinity) -> TextSelection

Dart copyWith(affinity:).

Source

pub fn is_directional(self, is_directional: bool) -> TextSelection

Dart copyWith(isDirectional:).

Source

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.

Source

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

Source§

fn clone(&self) -> TextSelection

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for TextSelection

Source§

impl Debug for TextSelection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for TextSelection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for TextSelection

Source§

impl From<TextSelection> for TextRange

Source§

fn from(selection: TextSelection) -> TextRange

Converts to this type from the input type.
Source§

impl Hash for TextSelection

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TextSelection

Source§

fn eq(&self, other: &TextSelection) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,