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
impl SelectionRef
pub fn new(selection: Selection) -> Self
pub fn is_range(&self) -> bool
pub fn is_node(&self) -> bool
Sourcepub fn table(&self) -> Option<TableSelection>
pub fn table(&self) -> Option<TableSelection>
The table selection’s value, None for any other selection.
Sourcepub fn get_start_end_points(&self) -> Option<(Point, Point)>
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.
Sourcepub fn range(&self) -> Option<RangeSelection>
pub fn range(&self) -> Option<RangeSelection>
The range selection’s value, None for a node selection.
Sourcepub fn node_keys(&self) -> Vec<String>
pub fn node_keys(&self) -> Vec<String>
A node selection’s keys, in the order added; empty for a range selection.
pub fn is_dirty(&self) -> bool
Sourcepub fn get_nodes(&self) -> Result<Vec<NodeRef>, LexicalError>
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.
Sourcepub fn get_text_content(&self) -> Result<String, LexicalError>
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.
Sourcepub fn clone_selection(&self) -> SelectionRef
pub fn clone_selection(&self) -> SelectionRef
selection.clone(): a separate selection with the same value, not
dirty.
pub fn ptr_eq(&self, other: &SelectionRef) -> bool
Sourcepub fn point_set(
&self,
which: Which,
key: &str,
offset: usize,
point_type: PointType,
) -> Result<(), LexicalError>
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.
Sourcepub fn is_backward(&self) -> Result<bool, LexicalError>
pub fn is_backward(&self) -> Result<bool, LexicalError>
isBackward(): whether the focus comes before the anchor.
Source§impl SelectionRef
impl SelectionRef
Sourcepub fn delete_character(&self, is_backward: bool) -> Result<(), LexicalError>
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.
Sourcepub fn delete_word(&self, is_backward: bool) -> Result<(), LexicalError>
pub fn delete_word(&self, is_backward: bool) -> Result<(), LexicalError>
selection.deleteWord(isBackward).
Sourcepub fn delete_line(&self, is_backward: bool) -> Result<(), LexicalError>
pub fn delete_line(&self, is_backward: bool) -> Result<(), LexicalError>
selection.deleteLine(isBackward).
Sourcepub fn delete_nodes(&self) -> Result<(), LexicalError>
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
impl SelectionRef
Sourcepub fn modify(
&self,
alter: SelectionAlter,
is_backward: bool,
granularity: SelectionGranularity,
) -> Result<(), LexicalError>
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
impl SelectionRef
Sourcepub fn toggle_format(&self, format_type: &str)
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.
Sourcepub fn set_format(&self, format: f64)
pub fn set_format(&self, format: f64)
setFormat(format): sets the selection’s pending format.
Sourcepub fn has_format(&self, format_type: &str) -> bool
pub fn has_format(&self, format_type: &str) -> bool
hasFormat(type): whether the pending format has format_type.
Sourcepub fn remove_text(&self) -> Result<(), LexicalError>
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.
Sourcepub fn extract(&self) -> Result<Vec<NodeRef>, LexicalError>
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
impl SelectionRef
Sourcepub fn format_text(
&self,
format_type: &str,
align_with_format: Option<f64>,
) -> Result<(), LexicalError>
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.
Sourcepub fn set_text_format(
&self,
formats: &[(&str, bool)],
) -> Result<(), LexicalError>
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).
Sourcepub fn get_character_offsets(&self) -> Result<(usize, usize), LexicalError>
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
impl SelectionRef
Sourcepub fn insert_nodes(&self, nodes: Vec<NodeRef>) -> Result<(), LexicalError>
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.
Sourcepub fn insert_raw_text(&self, text: &str) -> Result<(), LexicalError>
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.
Sourcepub fn insert_paragraph(&self) -> Result<Option<NodeRef>, LexicalError>
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.
Sourcepub fn insert_line_break(&self, select_start: bool) -> Result<(), LexicalError>
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
impl SelectionRef
Sourcepub fn insert_text(&self, text: &str) -> Result<(), LexicalError>
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
impl SelectionRef
Sourcepub fn table_has_format(&self, format_type: &str) -> Result<bool, LexicalError>
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.
Sourcepub fn get_table_shape(
&self,
) -> Result<Option<TableSelectionShape>, LexicalError>
pub fn get_table_shape( &self, ) -> Result<Option<TableSelectionShape>, LexicalError>
TableSelection.getShape(), deprecated upstream: the rectangle of the
anchor and focus cells’ positions.