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: StringThe current text being edited.
selection: TextSelectionThe 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: TextRangeThe 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
impl TextEditingValue
Sourcepub const EMPTY: TextEditingValue
pub const EMPTY: TextEditingValue
A value that corresponds to the empty string with no selection and no composing range.
Sourcepub fn new() -> TextEditingValue
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.
Sourcepub fn text(self, text: impl Into<String>) -> TextEditingValue
pub fn text(self, text: impl Into<String>) -> TextEditingValue
Dart TextEditingValue(text:).
Sourcepub fn selection(self, selection: TextSelection) -> TextEditingValue
pub fn selection(self, selection: TextSelection) -> TextEditingValue
Dart TextEditingValue(selection:).
Sourcepub fn composing(self, composing: TextRange) -> TextEditingValue
pub fn composing(self, composing: TextRange) -> TextEditingValue
Dart TextEditingValue(composing:).
Sourcepub fn copy_with(&self) -> TextEditingValue
pub fn copy_with(&self) -> TextEditingValue
Creates a copy of this value but with the given fields replaced with the new values.
Sourcepub fn is_composing_range_valid(&self) -> bool
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.
Sourcepub fn replaced(
&self,
replacement_range: impl Into<TextRange>,
replacement_string: &str,
) -> TextEditingValue
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
impl Clone for TextEditingValue
Source§impl Debug for TextEditingValue
impl Debug for TextEditingValue
Source§impl Default for TextEditingValue
impl Default for TextEditingValue
Source§fn default() -> TextEditingValue
fn default() -> TextEditingValue
Source§impl Display for TextEditingValue
impl Display for TextEditingValue
impl Eq for TextEditingValue
Source§impl Hash for TextEditingValue
impl Hash for TextEditingValue
Source§impl PartialEq for TextEditingValue
impl PartialEq for TextEditingValue
impl StructuralPartialEq for TextEditingValue
Auto Trait Implementations§
impl Freeze for TextEditingValue
impl RefUnwindSafe for TextEditingValue
impl Send for TextEditingValue
impl Sync for TextEditingValue
impl Unpin for TextEditingValue
impl UnsafeUnpin for TextEditingValue
impl UnwindSafe for TextEditingValue
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.