Struct zng_wgt_text::cmd::TextEditOp
source · pub struct TextEditOp(/* private fields */);
Expand description
Represents a text edit operation that can be send to an editable text using EDIT_CMD
.
Implementations§
source§impl TextEditOp
impl TextEditOp
sourcepub fn new<D>(
data: D,
op: impl FnMut(&mut D, UndoFullOp<'_>) + Send + 'static,
) -> Self
pub fn new<D>( data: D, op: impl FnMut(&mut D, UndoFullOp<'_>) + Send + 'static, ) -> Self
New text edit operation.
The editable text widget that handles EDIT_CMD
will call op
during event handling in
the node::resolve_text
context meaning the TEXT.resolved
and TEXT.resolve_caret
service is available in op
.
The text is edited by modifying ResolvedText::txt
. The text widget will detect changes to the caret and react s
accordingly (updating caret position and animation), the caret index is also snapped to the nearest grapheme start.
The op
arguments are a custom data D
and what UndoFullOp
to run, all
text edit operations must be undoable, first UndoOp::Redo
is called to “do”, then undo and redo again
if the user requests undo & redo. The text variable is always read-write when op
is called, more than
one op can be called before the text variable updates, and ResolvedText::pending_edit
is always false.
sourcepub fn insert(insert: impl Into<Txt>) -> Self
pub fn insert(insert: impl Into<Txt>) -> Self
Insert operation.
The insert
text is inserted at the current caret index or at 0
, or replaces the current selection,
after insert the caret is positioned after the inserted text.
sourcepub fn backspace() -> Self
pub fn backspace() -> Self
Remove one backspace range ending at the caret index, or removes the selection.
See SegmentedText::backspace_range
for more details about what is removed.
sourcepub fn backspace_word() -> Self
pub fn backspace_word() -> Self
Remove one backspace word range ending at the caret index, or removes the selection.
See SegmentedText::backspace_word_range
for more details about what is removed.
sourcepub fn delete() -> Self
pub fn delete() -> Self
Remove one delete range starting at the caret index, or removes the selection.
See SegmentedText::delete_range
for more details about what is removed.
sourcepub fn delete_word() -> Self
pub fn delete_word() -> Self
Remove one delete word range starting at the caret index, or removes the selection.
See SegmentedText::delete_word_range
for more details about what is removed.
sourcepub fn replace(
select_before: Range<usize>,
insert: impl Into<Txt>,
select_after: Range<usize>,
) -> Self
pub fn replace( select_before: Range<usize>, insert: impl Into<Txt>, select_after: Range<usize>, ) -> Self
Replace operation.
The select_before
is removed, and insert
inserted at the select_before.start
, after insertion
the select_after
is applied, you can use an empty insert to just remove.
All indexes are snapped to the nearest grapheme, you can use empty ranges to just position the caret.
sourcepub fn apply_transforms() -> Self
pub fn apply_transforms() -> Self
Applies TEXT_TRANSFORM_VAR
and WHITE_SPACE_VAR
to the text.
Trait Implementations§
source§impl Clone for TextEditOp
impl Clone for TextEditOp
source§fn clone(&self) -> TextEditOp
fn clone(&self) -> TextEditOp
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for TextEditOp
impl !RefUnwindSafe for TextEditOp
impl Send for TextEditOp
impl Sync for TextEditOp
impl Unpin for TextEditOp
impl !UnwindSafe for TextEditOp
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> FsChangeNote for T
impl<T> FsChangeNote for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more