Struct zng::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,
) -> TextEditOp
pub fn new<D>( data: D, op: impl FnMut(&mut D, UndoFullOp<'_>) + Send + 'static, ) -> TextEditOp
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>) -> TextEditOp
pub fn insert(insert: impl Into<Txt>) -> TextEditOp
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() -> TextEditOp
pub fn backspace() -> TextEditOp
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() -> TextEditOp
pub fn backspace_word() -> TextEditOp
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() -> TextEditOp
pub fn delete() -> TextEditOp
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() -> TextEditOp
pub fn delete_word() -> TextEditOp
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 clear() -> TextEditOp
pub fn clear() -> TextEditOp
Remove all the text.
sourcepub fn replace(
select_before: Range<usize>,
insert: impl Into<Txt>,
select_after: Range<usize>,
) -> TextEditOp
pub fn replace( select_before: Range<usize>, insert: impl Into<Txt>, select_after: Range<usize>, ) -> TextEditOp
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() -> TextEditOp
pub fn apply_transforms() -> TextEditOp
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
)§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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
.§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
.§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.§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.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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> 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 more