pub enum CommandFilter {
All,
ReadOnly,
ForwardOnly,
}Expand description
Command filter consulted before any cursor call in a surface’s keyboard layer.
Generic over the command vocabulary rather than duplicated per surface: the rule (“a read-only surface accepts everything that doesn’t mutate”) is the same for prose and for code, only the list of commands differs.
Variants§
All
Every command accepted (editor preset).
ReadOnly
Mutating commands rejected; navigation and copy/select-all accepted (read-only preset).
ForwardOnly
Additive editing only: the document may grow anywhere, but nothing the writer already committed can be taken away from the keyboard.
Deletes, word-deletes, cut and undo/redo are rejected; typing, pasting,
splitting blocks, formatting and every navigation command are accepted.
Unlike ReadOnly the surface is still a real editor —
caret, accessibility role and clipboard stay editable — so a host
swapping this in at runtime changes what the keyboard may do and nothing
else.
⚠ Rejecting commands is only half of the guarantee. Inserting over a
selection deletes it one layer below any command vocabulary (in
TextCursor::insert_text), so a surface honouring this filter must also
collapse the selection before inserting —
collapses_selection_before_insert
is that question, and RichTextEditor answers it at every insert site.
Implementations§
Source§impl CommandFilter
impl CommandFilter
pub fn accepts<C: EditorCommand>(&self, cmd: C) -> bool
Sourcepub fn collapses_selection_before_insert(&self) -> bool
pub fn collapses_selection_before_insert(&self) -> bool
Whether an insertion must first collapse the selection instead of replacing it.
True only for ForwardOnly. Type-over is a
delete that never passes through a command filter, so the insert sites
themselves ask this question and move the caret to the end of the
selection first — the typed text lands after the selected passage rather
than in place of it, and the keystroke is neither lost nor destructive.
Sourcepub fn allows_wholesale_replacement(&self) -> bool
pub fn allows_wholesale_replacement(&self) -> bool
Whether a command may replace document content wholesale (an
assistive-technology SetValue, which swaps the entire document for a
new string).
Only All permits it: under ReadOnly nothing may be
written, and under ForwardOnly a whole-document replacement is the
single most regressive edit there is, however additive the text arriving
with it looks.
Trait Implementations§
Source§impl Clone for CommandFilter
impl Clone for CommandFilter
Source§fn clone(&self) -> CommandFilter
fn clone(&self) -> CommandFilter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for CommandFilter
Source§impl Debug for CommandFilter
impl Debug for CommandFilter
impl Eq for CommandFilter
Source§impl PartialEq for CommandFilter
impl PartialEq for CommandFilter
Source§fn eq(&self, other: &CommandFilter) -> bool
fn eq(&self, other: &CommandFilter) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for CommandFilter
Auto Trait Implementations§
impl Freeze for CommandFilter
impl RefUnwindSafe for CommandFilter
impl Send for CommandFilter
impl Sync for CommandFilter
impl Unpin for CommandFilter
impl UnsafeUnpin for CommandFilter
impl UnwindSafe for CommandFilter
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
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,
§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
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
§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