pub struct TextEdit { /* private fields */ }Expand description
An editable line of text with a cursor and an optional selection.
Implementations§
Source§impl TextEdit
impl TextEdit
pub fn text(&self) -> String
Sourcepub fn chars(&self) -> &[char]
pub fn chars(&self) -> &[char]
The buffer itself. Callers that only need to measure or slice the text
use this instead of text, which allocates a fresh
String every call — and the platform’s input handler asks several
times per keystroke.
pub fn is_empty(&self) -> bool
Sourcepub fn set_cursor(&mut self, index: usize)
pub fn set_cursor(&mut self, index: usize)
Move the cursor, dropping any selection. Out-of-range values clamp.
Sourcepub fn set_selection(&mut self, start: usize, end: usize)
pub fn set_selection(&mut self, start: usize, end: usize)
Select start..end and leave the cursor at end, so a following
Shift+Arrow extends from the edge the user last moved.
Sourcepub fn extend_to(&mut self, index: usize)
pub fn extend_to(&mut self, index: usize)
Move the selection’s free edge to index, opening a selection anchored
at the cursor if there isn’t one. This is Shift+click and mouse drag.
Sourcepub fn set_text(&mut self, text: &str)
pub fn set_text(&mut self, text: &str)
Replace everything, as a programmatic set: the history is dropped because the old text is no longer something the user can undo back to. That also releases whatever the history was holding.
Sourcepub fn byte_of(&self, index: usize) -> usize
pub fn byte_of(&self, index: usize) -> usize
Byte offset into text for a char index. Shaped-line
geometry is addressed in bytes, the edit model in chars.
Sourcepub fn char_of(&self, byte: usize) -> usize
pub fn char_of(&self, byte: usize) -> usize
Char index for a byte offset, rounding up to the next char boundary.
Sourcepub fn word_at(&self, index: usize) -> (usize, usize)
pub fn word_at(&self, index: usize) -> (usize, usize)
The word surrounding index as (start, end) char indices — what a
double-click selects. A click in whitespace takes the whitespace run.
Sourcepub fn break_undo(&mut self)
pub fn break_undo(&mut self)
End the current coalescing run, so the next edit starts a fresh undo step. Callers use this at word boundaries and on paste.
Sourcepub fn selection(&self) -> Option<(usize, usize)>
pub fn selection(&self) -> Option<(usize, usize)>
The selected span (start, end) as char indices, or None if the
selection is empty/collapsed.
pub fn has_selection(&self) -> bool
Sourcepub fn selected_text(&self) -> Option<String>
pub fn selected_text(&self) -> Option<String>
The selected text, or None when nothing is selected.
Sourcepub fn select_all(&mut self)
pub fn select_all(&mut self)
Select the whole line.
Sourcepub fn clear_selection(&mut self)
pub fn clear_selection(&mut self)
Drop any selection, keeping the cursor put.
pub fn collapse_selection_start(&mut self) -> bool
pub fn collapse_selection_end(&mut self) -> bool
Sourcepub fn delete_selection(&mut self) -> bool
pub fn delete_selection(&mut self) -> bool
Delete the selected text (if any), leaving the cursor at its start. Returns whether anything was removed.
Sourcepub fn pre_move(&mut self, extend: bool)
pub fn pre_move(&mut self, extend: bool)
Prepare for a cursor move: with extend (Shift held) anchor a selection
at the current cursor if one isn’t already open; otherwise drop it.
Sourcepub fn split_selection(&self) -> Option<(String, String, String)>
pub fn split_selection(&self) -> Option<(String, String, String)>
The text split around the selection: (before, selected, after), or
None when nothing is selected.
Sourcepub fn insert(&mut self, s: &str)
pub fn insert(&mut self, s: &str)
Insert s at the cursor, replacing any selection, advancing past it.
Sourcepub fn replace_range(&mut self, range: Range<usize>, s: &str)
pub fn replace_range(&mut self, range: Range<usize>, s: &str)
Replace the char range range with s, leaving the cursor after it.
This is the entry point the platform’s text-input handler drives, so it
takes an explicit range rather than using the selection.
Sourcepub fn backspace(&mut self) -> bool
pub fn backspace(&mut self) -> bool
Delete the selection, or the char before the cursor. Returns whether anything changed.
Sourcepub fn delete(&mut self) -> bool
pub fn delete(&mut self) -> bool
Delete the selection, or the char at the cursor. Returns whether anything changed.
pub fn left(&mut self)
pub fn right(&mut self)
pub fn home(&mut self)
pub fn end(&mut self)
pub fn line_home(&mut self)
pub fn line_end(&mut self)
Sourcepub fn word_left(&mut self)
pub fn word_left(&mut self)
Move left to the start of the previous word (Option+Left on macOS).
Sourcepub fn word_right(&mut self)
pub fn word_right(&mut self)
Move right past the end of the next word (Option+Right on macOS).
Sourcepub fn delete_word_back(&mut self) -> bool
pub fn delete_word_back(&mut self) -> bool
Delete the word before the cursor (Option+Backspace). Returns whether anything changed.
Sourcepub fn delete_word_forward(&mut self) -> bool
pub fn delete_word_forward(&mut self) -> bool
Delete the word after the cursor (Option+Delete). Returns whether anything changed.
Sourcepub fn delete_to_start(&mut self) -> bool
pub fn delete_to_start(&mut self) -> bool
Delete from the cursor to the line start (Cmd+Backspace). Returns whether anything changed.
Sourcepub fn delete_to_end(&mut self) -> bool
pub fn delete_to_end(&mut self) -> bool
Delete from the cursor to the line end (Cmd+Delete / Ctrl+K). Returns whether anything changed.
Sourcepub fn split(&self) -> (String, String)
pub fn split(&self) -> (String, String)
The text before and after the cursor, for rendering a caret between.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TextEdit
impl RefUnwindSafe for TextEdit
impl Send for TextEdit
impl Sync for TextEdit
impl Unpin for TextEdit
impl UnsafeUnpin for TextEdit
impl UnwindSafe for TextEdit
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().