Skip to main content

Editor

Struct Editor 

Source
pub struct Editor(/* private fields */);
Expand description

A Lexical editor. A handle; cloning it shares the same editor. Without a DOM it is what JS calls a headless editor. It is neither Send nor Sync.

Implementations§

Source§

impl Editor

Source

pub const VERSION: &'static str = "lexical-rust@0.53.0"

LexicalEditor.version: the port’s own, as Swift’s is lexical-swift@<upstream>, for the upstream release in UPSTREAM_VERSION.

Source

pub fn config(&self) -> &EditorConfig

editor._config.

Source

pub fn is_composing(&self) -> bool

isComposing(): whether an input method is composing (_compositionKey is set).

Source

pub fn get_namespace(&self) -> &str

_config.namespace: the namespace the editor was created with.

Source

pub fn parent_editor(&self) -> Option<&Editor>

_parentEditor: the editor this one is nested in (CreateEditorArgs::parent_editor), if any.

Source

pub fn get_key(&self) -> &str

getKey(): the editor’s own random key (createUID()), which a drag from it is marked with ($writeDragSourceToDataTransfer).

Source

pub fn blur(&self)

blur(): the root element gives up the focus and its selection (RootElement::blur).

Source

pub fn focus( &self, callback: Option<Box<dyn FnOnce()>>, options: EditorFocusOptions, ) -> Result<(), LexicalError>

focus(callbackFn, options): with a root element, an update (tagged FOCUS_TAG) that marks the selection dirty, so the view applies it again, or selects the end (or, with EditorFocusOptions::RootStart, the start) of the root when there is none; callback runs once it commits. Without a root element it does nothing. (JS also turns autocapitalize off on the DOM root around the update, which only iOS’s keyboard reads.)

Source

pub fn is_headless(&self) -> bool

_headless: whether the editor never reconciles, as create_headless_editor makes it (and a nested editor of a headless one is).

Source

pub fn is_editable(&self) -> bool

isEditable().

Source

pub fn set_editable(&self, editable: bool)

setEditable(editable): when that changes the editor’s mode, the editable listeners hear of it.

Source

pub fn register_editable_listener<R: ListenerCleanup>( &self, listener: impl Fn(bool) -> R + 'static, ) -> Unregister

registerEditableListener(listener): listener hears each change of is_editable.

Source

pub fn get_decorators(&self) -> Decorators

getDecorators(): what each decorator decorated to (LexicalNode::decorate), as the reconciler last collected it. It is empty until the editor has a root element.

Source

pub fn register_decorator_listener<R: ListenerCleanup>( &self, listener: impl Fn(&Decorators) -> R + 'static, ) -> Unregister

registerDecoratorListener(listener): listener hears each commit that changed get_decorators, with the new decorators.

Source

pub fn get_root_element(&self) -> Option<RootElementRef>

getRootElement().

Source

pub fn set_root_element( &self, next_root_element: Option<RootElementRef>, ) -> Result<(), LexicalError>

setRootElement(nextRootElement), its model half: the editor is reset (its state is empty again) and the pending state, or the current one, is committed with history-merge, the queued updates and tags kept. With a root, every node is reconciled, so mutation listeners hear of each as created; then the root listeners run. Styling and events are the app’s view’s job.

Source

pub fn register_root_listener( &self, listener: impl Fn(Option<&RootElementRef>, Option<&RootElementRef>) -> Option<Unregister> + 'static, ) -> Unregister

registerRootListener(listener): listener is called at once with the root element (and None), then with the next and previous root each time it changes, and with None and the root when it is unregistered. What it returns runs before its next call.

Source

pub fn register_mutation_listener( &self, node_type: &str, listener: impl Fn(&NodeMutations, &MutationListenerPayload) + 'static, options: MutationListenerOptions, ) -> Result<Unregister, LexicalError>

registerMutationListener(klass, listener, options), by the node type: after each commit that the reconciler ran in (the editor has a root element), listener gets the class’s nodes it created, updated or destroyed. Unless skip_initialization, it is called at once with the class’s nodes in the editor’s state as created. Fails for a type the editor doesn’t register.

Source

pub fn get_registered_node(&self, node_type: &str) -> Option<NodeClass>

editor._nodes.get(type): the class the editor registers under the type.

Source

pub fn resolve_registered_node_after_replacements( &self, node_type: &str, ) -> Result<&'static str, LexicalError>

resolveRegisteredNodeAfterReplacements(registeredNode), by type: the type of the class a registered class’s replacements end at (following withKlass). Fails for a withKlass that isn’t registered.

Source

pub fn has_node(&self, node_type: &str) -> bool

hasNode(klass), by the node type: whether the editor registers it.

Source

pub fn has_nodes(&self, node_types: &[&str]) -> bool

hasNodes(klasses), by the node types: whether the editor registers all of them.

Source

pub fn set_selection_movement( &self, movement: Option<Rc<dyn SelectionMovement>>, )

Sets what stands in for the DOM’s Selection.modify in this editor: where a caret lands when modify, deleteCharacter, deleteWord or deleteLine move it within text, which only text layout knows. Without one (the default) the editor behaves as JS does with no root element: those moves fail with window object not found.

Source

pub fn get_editor_state(&self) -> EditorState

getEditorState(): the committed state.

Source

pub fn to_json(&self) -> Value

toJSON(): {editorState}, this editor’s committed state in the form the export around it is writing (is_compact_export), which is how a nested editor stays in the form of the document containing it.

Source

pub fn parse_editor_state( &self, json: &str, ) -> Result<EditorState, LexicalError>

parseEditorState(json) from the JSON text.

Source

pub fn parse_editor_state_json( &self, json: &Value, ) -> Result<EditorState, LexicalError>

parseEditorState(serializedEditorState) from parsed JSON.

Source

pub fn parse_editor_state_json_with( &self, json: &Value, update_fn: impl FnOnce() -> Result<(), LexicalError>, ) -> Result<EditorState, LexicalError>

parseEditorState(serializedEditorState, updateFn): runs update_fn on the parsed state before it is made read-only, as an update of that state ($getRoot() is its root); nothing it changes is marked dirty in this editor, nor in an update running here.

Source

pub fn update( &self, update_fn: impl FnOnce() -> Result<(), LexicalError> + 'static, options: UpdateOptions, ) -> Result<(), LexicalError>

update(updateFn, options). Inside another update of this editor (or a listener of its commit) the update is queued and runs after it, as in JS, which is why update_fn is 'static.

A non-discrete update is committed by the next read or discrete update, where JS commits it in a microtask. An update that fails is discarded, the editor keeps its previous state, and the error is returned (JS reports it to onError).

Source

pub fn set_editor_state( &self, editor_state: &EditorState, tag: Option<&str>, ) -> Result<(), LexicalError>

setEditorState(editorState, {tag}): makes editor_state the editor’s state, through an update, so a state from parse_editor_state has its text normalized and its transforms run, as in JS. The editor keeps its state and this returns the error when the update fails, such as for a state with nothing but the root (an invariant in JS’s DEV build).

Source

pub fn read<R>(&self, f: impl FnOnce() -> R) -> Result<R, LexicalError>

read(callbackFn): commits any pending update, then runs f with the editor’s state active, read-only. Fails when committing runs a queued update that fails.

Source

pub fn read_with_mode<R>( &self, mode: EditorReadMode, f: impl FnOnce() -> R, ) -> Result<R, LexicalError>

read(mode, callbackFn): read for EditorReadMode::ForceCommit; Latest reads the committed state without committing first, and Pending the state of the update in progress or queued (the committed one without one), without committing it.

Source

pub fn register_node_transform( &self, node_type: &'static str, transform: impl Fn(&NodeRef) -> Result<(), LexicalError> + 'static, ) -> Unregister

registerNodeTransform(klass, listener), by the node type. Nodes of that type already in the editor are marked dirty, so the transform runs on them with the next update. A class replaced by a with_klass (LexicalNodeReplacement) gets it on that class too.

Source

pub fn register_update_listener<R: ListenerCleanup>( &self, listener: impl Fn(&UpdateListenerPayload) -> R + 'static, ) -> Unregister

registerUpdateListener(listener).

Source

pub fn register_text_content_listener<R: ListenerCleanup>( &self, listener: impl Fn(&str) -> R + 'static, ) -> Unregister

registerTextContentListener(listener).

Source

pub fn register_command<P: 'static>( &self, command: &LexicalCommand<P>, listener: impl Fn(&P, &Editor) -> Result<bool, LexicalError> + 'static, priority: i8, ) -> Unregister

registerCommand(command, listener, priority), priority being one of the COMMAND_PRIORITY_* constants: 0 to 4 add the listener to the end of that priority’s queue, and the COMMAND_PRIORITY_BEFORE_* ones (-8 to -4) to its beginning (normalizePriority’s priority & 7).

Source

pub fn dispatch_command<P: 'static>( &self, command: &LexicalCommand<P>, payload: P, ) -> Result<bool, LexicalError>

dispatchCommand(command, payload): runs the command’s listeners, by priority (within each, this editor’s, then its parent editors’), until one handles it, and returns whether one did.

Trait Implementations§

Source§

impl Clone for Editor

Source§

fn clone(&self) -> Self

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 Eq for Editor

Source§

impl PartialEq for Editor

Editors compare by identity, as JS compares them with ===.

Source§

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

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

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Editor

§

impl !Send for Editor

§

impl !Sync for Editor

§

impl !UnwindSafe for Editor

§

impl Forget for Editor

§

impl Freeze for Editor

§

impl Move for Editor

§

impl Unpin for Editor

§

impl UnsafeUnpin for Editor

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<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> SignalValue for T
where T: Clone + PartialEq + 'static,

Source§

fn is_same(&self, other: &T) -> bool

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.