pub struct TextCursor { /* private fields */ }Expand description
A cursor into a TextDocument.
Multiple cursors can coexist on the same document (like Qt’s QTextCursor).
When any cursor edits text, all other cursors’ positions are automatically
adjusted by the document.
Cloning a cursor creates an independent cursor at the same position.
Implementations§
Source§impl TextCursor
impl TextCursor
Sourcepub fn has_selection(&self) -> bool
pub fn has_selection(&self) -> bool
Returns true if there is a selection.
Sourcepub fn selection_start(&self) -> usize
pub fn selection_start(&self) -> usize
Start of the selection (min of position and anchor).
Sourcepub fn selection_end(&self) -> usize
pub fn selection_end(&self) -> usize
End of the selection (max of position and anchor).
Sourcepub fn selected_text(&self) -> Result<String>
pub fn selected_text(&self) -> Result<String>
Get the selected text. Returns empty string if no selection.
Sourcepub fn clear_selection(&self)
pub fn clear_selection(&self)
Collapse the selection by moving anchor to position.
Sourcepub fn at_block_start(&self) -> bool
pub fn at_block_start(&self) -> bool
True if the cursor is at the start of a block.
Sourcepub fn at_block_end(&self) -> bool
pub fn at_block_end(&self) -> bool
True if the cursor is at the end of a block.
Sourcepub fn block_number(&self) -> usize
pub fn block_number(&self) -> usize
The block number (0-indexed) containing the cursor.
Sourcepub fn position_in_block(&self) -> usize
pub fn position_in_block(&self) -> usize
The cursor’s column within the current block (0-indexed).
Sourcepub fn set_position(&self, position: usize, mode: MoveMode)
pub fn set_position(&self, position: usize, mode: MoveMode)
Set the cursor to an absolute position.
Sourcepub fn move_position(
&self,
operation: MoveOperation,
mode: MoveMode,
n: usize,
) -> bool
pub fn move_position( &self, operation: MoveOperation, mode: MoveMode, n: usize, ) -> bool
Move the cursor by a semantic operation.
n is used as a repeat count for character-level movements
(NextCharacter, PreviousCharacter, Left, Right).
For all other operations it is ignored. Returns true if the cursor moved.
Sourcepub fn select(&self, selection: SelectionType)
pub fn select(&self, selection: SelectionType)
Select a region relative to the cursor position.
Sourcepub fn insert_text(&self, text: &str) -> Result<()>
pub fn insert_text(&self, text: &str) -> Result<()>
Insert plain text at the cursor. Replaces selection if any.
Sourcepub fn insert_formatted_text(
&self,
text: &str,
format: &TextFormat,
) -> Result<()>
pub fn insert_formatted_text( &self, text: &str, format: &TextFormat, ) -> Result<()>
Insert text with a specific character format. Replaces selection if any.
Sourcepub fn insert_block(&self) -> Result<()>
pub fn insert_block(&self) -> Result<()>
Insert a block break (new paragraph). Replaces selection if any.
Sourcepub fn insert_html(&self, html: &str) -> Result<()>
pub fn insert_html(&self, html: &str) -> Result<()>
Insert an HTML fragment at the cursor position. Replaces selection if any.
Sourcepub fn insert_markdown(&self, markdown: &str) -> Result<()>
pub fn insert_markdown(&self, markdown: &str) -> Result<()>
Insert a Markdown fragment at the cursor position. Replaces selection if any.
Sourcepub fn insert_fragment(&self, fragment: &DocumentFragment) -> Result<()>
pub fn insert_fragment(&self, fragment: &DocumentFragment) -> Result<()>
Insert a document fragment at the cursor. Replaces selection if any.
Sourcepub fn selection(&self) -> DocumentFragment
pub fn selection(&self) -> DocumentFragment
Extract the current selection as a DocumentFragment.
Sourcepub fn insert_image(&self, name: &str, width: u32, height: u32) -> Result<()>
pub fn insert_image(&self, name: &str, width: u32, height: u32) -> Result<()>
Insert an image at the cursor.
Sourcepub fn insert_frame(&self) -> Result<()>
pub fn insert_frame(&self) -> Result<()>
Insert a new frame at the cursor.
Sourcepub fn insert_table(&self, rows: usize, columns: usize) -> Result<TextTable>
pub fn insert_table(&self, rows: usize, columns: usize) -> Result<TextTable>
Insert a table at the cursor position.
Creates a rows × columns table with empty cells.
The cursor moves to after the table.
Returns a handle to the created table.
Sourcepub fn current_table(&self) -> Option<TextTable>
pub fn current_table(&self) -> Option<TextTable>
Returns the table the cursor is currently inside, if any.
Returns None if the cursor is in the main document flow
(not inside a table cell).
Sourcepub fn current_table_cell(&self) -> Option<TableCellRef>
pub fn current_table_cell(&self) -> Option<TableCellRef>
Returns the table cell the cursor is currently inside, if any.
Returns None if the cursor is not inside a table cell.
When Some, provides the table, row, and column.
Sourcepub fn remove_table(&self, table_id: usize) -> Result<()>
pub fn remove_table(&self, table_id: usize) -> Result<()>
Remove a table from the document by its ID.
Sourcepub fn insert_table_row(&self, table_id: usize, row_index: usize) -> Result<()>
pub fn insert_table_row(&self, table_id: usize, row_index: usize) -> Result<()>
Insert a row into a table at the given index.
Sourcepub fn insert_table_column(
&self,
table_id: usize,
column_index: usize,
) -> Result<()>
pub fn insert_table_column( &self, table_id: usize, column_index: usize, ) -> Result<()>
Insert a column into a table at the given index.
Sourcepub fn remove_table_row(&self, table_id: usize, row_index: usize) -> Result<()>
pub fn remove_table_row(&self, table_id: usize, row_index: usize) -> Result<()>
Remove a row from a table. Fails if only one row remains.
Sourcepub fn remove_table_column(
&self,
table_id: usize,
column_index: usize,
) -> Result<()>
pub fn remove_table_column( &self, table_id: usize, column_index: usize, ) -> Result<()>
Remove a column from a table. Fails if only one column remains.
Sourcepub fn merge_table_cells(
&self,
table_id: usize,
start_row: usize,
start_column: usize,
end_row: usize,
end_column: usize,
) -> Result<()>
pub fn merge_table_cells( &self, table_id: usize, start_row: usize, start_column: usize, end_row: usize, end_column: usize, ) -> Result<()>
Merge a rectangular range of cells within a table.
Sourcepub fn split_table_cell(
&self,
cell_id: usize,
split_rows: usize,
split_columns: usize,
) -> Result<()>
pub fn split_table_cell( &self, cell_id: usize, split_rows: usize, split_columns: usize, ) -> Result<()>
Split a previously merged cell.
Sourcepub fn set_table_format(
&self,
table_id: usize,
format: &TableFormat,
) -> Result<()>
pub fn set_table_format( &self, table_id: usize, format: &TableFormat, ) -> Result<()>
Set formatting on a table.
Sourcepub fn set_table_cell_format(
&self,
cell_id: usize,
format: &CellFormat,
) -> Result<()>
pub fn set_table_cell_format( &self, cell_id: usize, format: &CellFormat, ) -> Result<()>
Set formatting on a table cell.
Sourcepub fn remove_current_table(&self) -> Result<()>
pub fn remove_current_table(&self) -> Result<()>
Remove the table the cursor is currently inside. Returns an error if the cursor is not inside a table.
Sourcepub fn insert_row_above(&self) -> Result<()>
pub fn insert_row_above(&self) -> Result<()>
Insert a row above the cursor’s current row. Returns an error if the cursor is not inside a table.
Sourcepub fn insert_row_below(&self) -> Result<()>
pub fn insert_row_below(&self) -> Result<()>
Insert a row below the cursor’s current row. Returns an error if the cursor is not inside a table.
Sourcepub fn insert_column_before(&self) -> Result<()>
pub fn insert_column_before(&self) -> Result<()>
Insert a column before the cursor’s current column. Returns an error if the cursor is not inside a table.
Sourcepub fn insert_column_after(&self) -> Result<()>
pub fn insert_column_after(&self) -> Result<()>
Insert a column after the cursor’s current column. Returns an error if the cursor is not inside a table.
Sourcepub fn remove_current_row(&self) -> Result<()>
pub fn remove_current_row(&self) -> Result<()>
Remove the row at the cursor’s current position. Returns an error if the cursor is not inside a table.
Sourcepub fn remove_current_column(&self) -> Result<()>
pub fn remove_current_column(&self) -> Result<()>
Remove the column at the cursor’s current position. Returns an error if the cursor is not inside a table.
Sourcepub fn merge_selected_cells(&self) -> Result<()>
pub fn merge_selected_cells(&self) -> Result<()>
Merge cells spanned by the current selection.
Both cursor position and anchor must be inside the same table. The cell range is derived from the cells at position and anchor. Returns an error if the cursor is not inside a table or position and anchor are in different tables.
Sourcepub fn split_current_cell(
&self,
split_rows: usize,
split_columns: usize,
) -> Result<()>
pub fn split_current_cell( &self, split_rows: usize, split_columns: usize, ) -> Result<()>
Split the cell at the cursor’s current position. Returns an error if the cursor is not inside a table.
Sourcepub fn set_current_table_format(&self, format: &TableFormat) -> Result<()>
pub fn set_current_table_format(&self, format: &TableFormat) -> Result<()>
Set formatting on the table the cursor is currently inside. Returns an error if the cursor is not inside a table.
Sourcepub fn set_current_cell_format(&self, format: &CellFormat) -> Result<()>
pub fn set_current_cell_format(&self, format: &CellFormat) -> Result<()>
Set formatting on the cell the cursor is currently inside. Returns an error if the cursor is not inside a table.
Sourcepub fn delete_char(&self) -> Result<()>
pub fn delete_char(&self) -> Result<()>
Delete the character after the cursor (Delete key).
Sourcepub fn delete_previous_char(&self) -> Result<()>
pub fn delete_previous_char(&self) -> Result<()>
Delete the character before the cursor (Backspace key).
Sourcepub fn remove_selected_text(&self) -> Result<String>
pub fn remove_selected_text(&self) -> Result<String>
Delete the selected text. Returns the deleted text. No-op if no selection.
Sourcepub fn create_list(&self, style: ListStyle) -> Result<()>
pub fn create_list(&self, style: ListStyle) -> Result<()>
Turn the block(s) in the selection into a list.
Sourcepub fn insert_list(&self, style: ListStyle) -> Result<()>
pub fn insert_list(&self, style: ListStyle) -> Result<()>
Insert a new list item at the cursor position.
Sourcepub fn char_format(&self) -> Result<TextFormat>
pub fn char_format(&self) -> Result<TextFormat>
Get the character format at the cursor position.
Sourcepub fn block_format(&self) -> Result<BlockFormat>
pub fn block_format(&self) -> Result<BlockFormat>
Get the block format of the block containing the cursor.
Sourcepub fn set_char_format(&self, format: &TextFormat) -> Result<()>
pub fn set_char_format(&self, format: &TextFormat) -> Result<()>
Set the character format for the selection.
Sourcepub fn merge_char_format(&self, format: &TextFormat) -> Result<()>
pub fn merge_char_format(&self, format: &TextFormat) -> Result<()>
Merge a character format into the selection.
Sourcepub fn set_block_format(&self, format: &BlockFormat) -> Result<()>
pub fn set_block_format(&self, format: &BlockFormat) -> Result<()>
Set the block format for the current block (or all blocks in selection).
Sourcepub fn set_frame_format(
&self,
frame_id: usize,
format: &FrameFormat,
) -> Result<()>
pub fn set_frame_format( &self, frame_id: usize, format: &FrameFormat, ) -> Result<()>
Set the frame format.
Sourcepub fn begin_edit_block(&self)
pub fn begin_edit_block(&self)
Begin a group of operations that will be undone as a single unit.
Sourcepub fn end_edit_block(&self)
pub fn end_edit_block(&self)
End the current edit block.
Sourcepub fn join_previous_edit_block(&self)
pub fn join_previous_edit_block(&self)
Alias for begin_edit_block.
Semantically indicates that the new composite should be merged with
the previous one (e.g., consecutive keystrokes grouped into a single
undo unit). The current backend treats this identically to
begin_edit_block; future versions may implement automatic merging.