Skip to main content

InsertionOrigin

Enum InsertionOrigin 

Source
pub enum InsertionOrigin {
    Unspecified,
    Typed,
    Composed,
    Pasted,
    Dropped,
    Imported,
    Replayed,
    Programmatic,
    Assistive,
}
Expand description

Events emitted by a TextDocument.

Subscribe via TextDocument::on_change (callback-based) or poll via TextDocument::poll_events (frame-loop).

These events carry enough information for a UI to do incremental updates — repaint only the affected region, not the entire document. Which channel some text arrived through.

A fact about how the characters reached the document, and nothing more. It says who typed, pasted or dictated nothing at all: an application can only report the channel it was called through, and the inference from a channel to an author is not one any of this can make.

§Why the default is Unspecified and not Programmatic

Every insertion method has a plain form and a _with_origin sibling. The plain form reports Unspecified, which means the caller did not say — deliberately not Programmatic, which would assert that the application inserted the text itself. Those are different claims, and a consumer counting them apart is entitled to know which one it has.

The same distinction as an absent field versus a zero: an unspecified origin is missing information, and a wrong one is a wrong fact.

Variants§

§

Unspecified

The caller did not say. The default for every plain insertion method.

§

Typed

Entered a key at a time.

§

Composed

Committed by an input method — the multi-keystroke path that produces one character. Kept apart from Typed because a consumer counting keystrokes and one counting characters disagree here, and both are right.

§

Pasted

Pasted from a clipboard.

§

Dropped

Dropped in from elsewhere.

§

Imported

Brought in by a document import.

§

Replayed

Re-applied by undo or redo.

Hard-coded at those two paths, which never re-enter the insertion API — they snapshot and diff instead — so a replayed edit can never be counted twice under its original origin.

§

Programmatic

Inserted by the application: a template, an expansion, a substitution.

§

Assistive

Arrived through an accessibility channel: dictation, a braille display.

Never folded into Typed. Some people write this way, and a record that erased the distinction would be reporting them as something they are not.

Implementations§

Source§

impl InsertionOrigin

Source

pub const ALL: [InsertionOrigin; 9]

Every variant, for a consumer building a table over them.

Source

pub fn token(self) -> &'static str

A stable lower-case token, for anything that has to write one down.

Spelled out rather than derived from the variant name, so renaming a variant cannot silently change what a consumer persisted.

Trait Implementations§

Source§

impl Clone for InsertionOrigin

Source§

fn clone(&self) -> InsertionOrigin

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for InsertionOrigin

Source§

impl Debug for InsertionOrigin

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for InsertionOrigin

Source§

fn default() -> InsertionOrigin

Returns the “default value” for a type. Read more
Source§

impl Eq for InsertionOrigin

Source§

impl Hash for InsertionOrigin

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for InsertionOrigin

Source§

fn eq(&self, other: &InsertionOrigin) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for InsertionOrigin

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.