Skip to main content

SelectionRef

Struct SelectionRef 

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

A selection object, shared as JS shares it: $getSelection() returns the one the editor state holds, so a change through it is a change of the state’s selection; clone_selection makes a separate one.

Implementations§

Source§

impl SelectionRef

Source

pub fn new(selection: Selection) -> Self

Source

pub fn get(&self) -> Selection

The selection’s current value.

Source

pub fn is_range(&self) -> bool

Source

pub fn is_node(&self) -> bool

Source

pub fn is_table(&self) -> bool

$isTableSelection(selection).

Source

pub fn table(&self) -> Option<TableSelection>

The table selection’s value, None for any other selection.

Source

pub fn get_start_end_points(&self) -> Option<(Point, Point)>

selection.getStartEndPoints(): the anchor and focus of a range or table selection, None for a node selection.

Source

pub fn range(&self) -> Option<RangeSelection>

The range selection’s value, None for a node selection.

Source

pub fn add(&self, key: &str)

nodeSelection.add(key); nothing on a range selection.

Source

pub fn delete(&self, key: &str)

nodeSelection.delete(key); nothing on a range selection.

Source

pub fn clear(&self)

nodeSelection.clear(); nothing on a range selection.

Source

pub fn node_keys(&self) -> Vec<String>

A node selection’s keys, in the order added; empty for a range selection.

Source

pub fn point(&self, which: Which) -> Option<Point>

The point which of a range selection.

Source

pub fn is_dirty(&self) -> bool

Source

pub fn get_nodes(&self) -> Result<Vec<NodeRef>, LexicalError>

selection.getNodes(): for a range selection, the nodes it covers in document order, with the quirks of the original getNodes ($getNodesFromCaretRangeCompat); for a node selection, its nodes that exist, in the order added. Cached until the selection or a node changes.

Source

pub fn get_text_content(&self) -> Result<String, LexicalError>

selection.getTextContent(): for a range selection, the text it covers, with a line break between blocks; for a node selection, the text of its nodes.

Source

pub fn clone_selection(&self) -> SelectionRef

selection.clone(): a separate selection with the same value, not dirty.

Source

pub fn ptr_eq(&self, other: &SelectionRef) -> bool

Source

pub fn point_set( &self, which: Which, key: &str, offset: usize, point_type: PointType, ) -> Result<(), LexicalError>

point.set(key, offset, type) on the point which of a range selection; nothing on a node selection.

Source

pub fn is_backward(&self) -> Result<bool, LexicalError>

isBackward(): whether the focus comes before the anchor.

Source§

impl SelectionRef

Source

pub fn delete_character(&self, is_backward: bool) -> Result<(), LexicalError>

selection.deleteCharacter(isBackward): deletes one character, or the selected content, and handles the boundaries of blocks.

Source

pub fn delete_word(&self, is_backward: bool) -> Result<(), LexicalError>

selection.deleteWord(isBackward).

Source

pub fn delete_line(&self, is_backward: bool) -> Result<(), LexicalError>

selection.deleteLine(isBackward).

Source

pub fn delete_nodes(&self) -> Result<(), LexicalError>

NodeSelection.deleteNodes(): removes the selected nodes, first moving the selection to just after the first of them when this is the current (or last committed) selection, and gives an emptied root a paragraph. Slotted nodes are fixed parts of their host, and are left alone.

Source§

impl SelectionRef

Source

pub fn modify( &self, alter: SelectionAlter, is_backward: bool, granularity: SelectionGranularity, ) -> Result<(), LexicalError>

selection.modify(alter, isBackward, granularity): moves (collapsed) or extends the selection by one unit, across decorators and blocks in the model and otherwise where the editor’s SelectionMovement lands. Without a movement this fails with window object not found unless the model step handled it, as JS does with no root element.

Source§

impl SelectionRef

Source

pub fn toggle_format(&self, format_type: &str)

toggleFormat(format): toggles a format on the selection’s pending format, the one text typed at a collapsed selection gets.

Source

pub fn set_format(&self, format: f64)

setFormat(format): sets the selection’s pending format.

Source

pub fn set_style(&self, style: &str)

setStyle(style): sets the selection’s pending style.

Source

pub fn has_format(&self, format_type: &str) -> bool

hasFormat(type): whether the pending format has format_type.

Source

pub fn remove_text(&self) -> Result<(), LexicalError>

removeText(): removes the selected content and collapses the selection where it was. When the caret lands in another node, the pending format and style come from that node.

Source

pub fn extract(&self) -> Result<Vec<NodeRef>, LexicalError>

extract(): the selected nodes, with the text nodes at the ends of a range selection split so that only the selected text is returned. A range over part of one text node then covers that whole node. For a node selection, its nodes (NodeSelection.extract()).

Source§

impl SelectionRef

Source

pub fn format_text( &self, format_type: &str, align_with_format: Option<f64>, ) -> Result<(), LexicalError>

selection.formatText(formatType, alignWithFormat) ($formatText(selection, formatType, alignWithFormat)): toggles format_type on the selected text, splitting text nodes at the selection’s edges, and aligns every node with the same target. On a collapsed selection (or one without text) it toggles the pending format instead.

Without align_with_format, a range selection aligns with its pending format toggled, so the type is added unless the pending format has it; a node selection toggles each node on its own.

Source

pub fn set_text_format( &self, formats: &[(&str, bool)], ) -> Result<(), LexicalError>

$setTextFormat(selection, formats): sets (true) or clears (false) each format type on the selection, in order, so a later entry wins over an exclusive earlier one (subscript and superscript, the case transforms).

Source

pub fn get_character_offsets(&self) -> Result<(usize, usize), LexicalError>

$getCharacterOffsets(selection): the anchor’s and focus’s offsets in characters; an element point counts as the end of the element’s text when it is after its last child, and 0 otherwise. A collapsed element selection and a node selection give (0, 0).

Source§

impl SelectionRef

Source

pub fn insert_nodes(&self, nodes: Vec<NodeRef>) -> Result<(), LexicalError>

selection.insertNodes(nodes): RangeSelection.insertNodes, which replaces the selected content with nodes, splitting blocks as needed, and selects the end of what it inserted; or NodeSelection.insertNodes, which inserts them after the last selected node and removes the selected nodes.

Source

pub fn insert_raw_text(&self, text: &str) -> Result<(), LexicalError>

selection.insertRawText(text): on a range selection, inserts the text with its tabs and line breaks as nodes; on a node selection, nothing.

Source

pub fn insert_paragraph(&self) -> Result<Option<NodeRef>, LexicalError>

selection.insertParagraph(): splits the block at the selection, and returns the new block, if one was inserted, with the selection at its start.

Source

pub fn insert_line_break(&self, select_start: bool) -> Result<(), LexicalError>

selection.insertLineBreak(selectStart): inserts a line break, with the selection after it, or before it when select_start.

Source§

impl SelectionRef

Source

pub fn insert_text(&self, text: &str) -> Result<(), LexicalError>

selection.insertText(text): inserts text at a range selection, replacing what it covers; nothing for a node selection (NodeSelection.insertText()).

Source§

impl SelectionRef

Source

pub fn table_has_format(&self, format_type: &str) -> Result<bool, LexicalError>

TableSelection.hasFormat(type): whether the first paragraph of any selected cell has the format. False for any other selection.

Source

pub fn get_table_shape( &self, ) -> Result<Option<TableSelectionShape>, LexicalError>

TableSelection.getShape(), deprecated upstream: the rectangle of the anchor and focus cells’ positions.

Trait Implementations§

Source§

impl Clone for SelectionRef

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 Debug for SelectionRef

Source§

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

Formats the value using the given formatter. Read more

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<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> 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.