Skip to main content

TextEditingValue

Struct TextEditingValue 

Source
pub struct TextEditingValue {
    pub text: String,
    pub selection: TextSelection,
    pub composing: TextRange,
}
Expand description

The current text, selection, and composing state for editing a run of text.

Fields§

§text: String

The current text being edited.

§selection: TextSelection

The range of text that is currently selected.

When selection is a TextSelection that has the same non-negative baseOffset and extentOffset, the selection property represents the caret position.

If the current selection has a negative baseOffset or extentOffset, then the text currently does not have a selection or a caret location, and most text editing operations that rely on the current selection (for instance, insert a character at the caret location) will do nothing.

§composing: TextRange

The range of text that is still being composed.

Composing regions are created by input methods (IMEs) to indicate the text within a certain range is provisional. For instance, the Android Gboard app’s English keyboard puts the current word under the caret into a composing region to indicate the word is subject to autocorrect or prediction changes.

Composing regions can also be used for performing multistage input, which is typically used by IMEs designed for phonetic keyboard to enter ideographic symbols. As an example, many CJK keyboards require the user to enter a Latin alphabet sequence and then convert it to CJK characters. On iOS, the default software keyboards do not have a dedicated view to show the unfinished Latin sequence, so it’s displayed directly in the text field, inside of a composing region.

On iOS 17 and later, the composing region can also be used to display inline text predictions. The user can accept the predicted text by tapping the Space bar.

The composing region should typically only be changed by the IME, or the user via interacting with the IME.

If the range represented by this property is TextRange::EMPTY, then the text is not currently being composed.

Implementations§

Source§

impl TextEditingValue

Source

pub const EMPTY: TextEditingValue

A value that corresponds to the empty string with no selection and no composing range.

Source

pub fn new() -> TextEditingValue

Creates information for editing a run of text.

The selection and composing range must be within the text. This is not checked during construction, and must be guaranteed by the caller.

The default value of selection is TextSelection::collapsed(-1, …). This indicates that there is no selection at all.

Source

pub fn text(self, text: impl Into<String>) -> TextEditingValue

Dart TextEditingValue(text:).

Source

pub fn selection(self, selection: TextSelection) -> TextEditingValue

Dart TextEditingValue(selection:).

Source

pub fn composing(self, composing: TextRange) -> TextEditingValue

Dart TextEditingValue(composing:).

Source

pub fn copy_with(&self) -> TextEditingValue

Creates a copy of this value but with the given fields replaced with the new values.

Source

pub fn is_composing_range_valid(&self) -> bool

Whether the composing range is a valid range within text.

Returns true if and only if the composing range is normalized, its start is greater than or equal to 0, and its end is less than or equal to text’s length.

If this property is false while the composing range’s isValid is true, it usually indicates the current composing range is invalid because of a programming error.

Source

pub fn replaced( &self, replacement_range: impl Into<TextRange>, replacement_string: &str, ) -> TextEditingValue

Returns a new TextEditingValue, which is this TextEditingValue with its text partially replaced by the replacement_string.

The replacement_range parameter specifies the range of the text that needs to be replaced.

The replacement_string parameter specifies the string to replace the given range of text with.

This method also adjusts the selection range and the composing range of the resulting TextEditingValue, such that they point to the same substrings as the corresponding ranges in the original TextEditingValue. For example, if the original TextEditingValue is “Hello world” with the word “world” selected, replacing “Hello” with a different string using this method will not change the selected word.

This method does nothing if the given replacement_range is not TextRange::is_valid.

Trait Implementations§

Source§

impl Clone for TextEditingValue

Source§

fn clone(&self) -> Self

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 Debug for TextEditingValue

Source§

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

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

impl Default for TextEditingValue

Source§

fn default() -> TextEditingValue

Returns the “default value” for a type. Read more
Source§

impl Display for TextEditingValue

Source§

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

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

impl Eq for TextEditingValue

Source§

impl Hash for TextEditingValue

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 TextEditingValue

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TextEditingValue

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,