pub struct BlockEditorModel { /* private fields */ }Expand description
Headless editor facade (spike name). Phase 3 wraps this in the
BlockEditorState entity.
Implementations§
Source§impl BlockEditorModel
impl BlockEditorModel
Sourcepub fn insert_text(
&mut self,
text: &str,
origin: EditOrigin,
) -> Result<(), CommandError>
pub fn insert_text( &mut self, text: &str, origin: EditOrigin, ) -> Result<(), CommandError>
Insert plain text at the selection (replacing it); \n splits blocks.
Sourcepub fn paste_inline_markdown(
&mut self,
text: &str,
) -> Result<bool, CommandError>
pub fn paste_inline_markdown( &mut self, text: &str, ) -> Result<bool, CommandError>
Paste the editor’s own inline Markdown copy (D17): each line is
parsed as inline Markdown (marks survive), lines become blocks as
typed. Edge whitespace stays literal. One undo step. In a code block
the marks are dropped (the text is inserted raw); Ok(false) when
the target cannot take it (a table cell with several lines).
Sourcepub fn delete(&mut self, forward: bool) -> Result<(), CommandError>
pub fn delete(&mut self, forward: bool) -> Result<(), CommandError>
Backspace (forward == false) or Delete: a grapheme, the selection, a join with the neighbouring block, or (next to a table) select the table.
Sourcepub fn split_block(&mut self) -> Result<(), CommandError>
pub fn split_block(&mut self) -> Result<(), CommandError>
Enter: split the text block (in a list, a new item; in an empty item, exit or outdent).
Sourcepub fn paste_blocks(&mut self, text: &str) -> Result<bool, CommandError>
pub fn paste_blocks(&mut self, text: &str) -> Result<bool, CommandError>
Paste Markdown as blocks, as one undo step. Text without a line
break, or that parses to a single paragraph, is left to plain
insertion (insert_text). Otherwise the text is parsed: a
leading paragraph merges into the text before the caret, a trailing
one into the text after it, and the blocks between are inserted
between the two halves. Returns whether it applied (false for
single-line text or when the caret is not in an editable text block;
the caller then inserts plain text).
Sourcepub fn run(&mut self, command: EditorCommand) -> Result<bool, CommandError>
pub fn run(&mut self, command: EditorCommand) -> Result<bool, CommandError>
Run an EditorCommand; returns whether the document or selection changed.
Source§impl BlockEditorModel
impl BlockEditorModel
Sourcepub fn from_markdown(
source: &str,
extensions: MarkdownExtensions,
) -> Result<Self, SharedString>
pub fn from_markdown( source: &str, extensions: MarkdownExtensions, ) -> Result<Self, SharedString>
Parse Markdown into a model.
Sourcepub fn set_source(&mut self, source: &str) -> Result<(), SharedString>
pub fn set_source(&mut self, source: &str) -> Result<(), SharedString>
Replace the content. Fresh ids (old positions fail with
UnknownBlock), history cleared.
Sourcepub fn document(&self) -> DocumentRef<'_>
pub fn document(&self) -> DocumentRef<'_>
Read-only view of the block tree.
Sourcepub fn selection(&self) -> &BlockSelection
pub fn selection(&self) -> &BlockSelection
The current selection.
Sourcepub fn set_selection(
&mut self,
selection: BlockSelection,
) -> Result<(), SelectionError>
pub fn set_selection( &mut self, selection: BlockSelection, ) -> Result<(), SelectionError>
Set the selection after validating it against the document.
Sourcepub fn caret(&self) -> Option<BlockPosition>
pub fn caret(&self) -> Option<BlockPosition>
The caret (head of a text selection); None for a block selection.
Sourcepub fn active_marks(&self) -> MarkSet
pub fn active_marks(&self) -> MarkSet
Marks the next typed text gets (stored marks, else inherited at the caret).
Sourcepub fn mark_state(&self, kind: MarkKind) -> MarkState
pub fn mark_state(&self, kind: MarkKind) -> MarkState
Whether kind is on, off or mixed over the selection.
Sourcepub fn block_kind_at_caret(&self) -> Option<BlockKind>
pub fn block_kind_at_caret(&self) -> Option<BlockKind>
Kind of the text block holding the caret, if any.
Sourcepub fn break_coalescing(&mut self)
pub fn break_coalescing(&mut self)
End the current typing group, so the next edit is its own undo step.
Source§impl BlockEditorModel
impl BlockEditorModel
pub fn source_snapshot(&self) -> SourceSnapshot
Sourcepub fn capture_caret(&self) -> Result<CapturedRange, CapturedRangeError>
pub fn capture_caret(&self) -> Result<CapturedRange, CapturedRangeError>
Capture the head/caret, inserting there even when text is selected.
Sourcepub fn capture_selection(&self) -> Result<CapturedRange, CapturedRangeError>
pub fn capture_selection(&self) -> Result<CapturedRange, CapturedRangeError>
Capture the current text selection for one atomic replacement.
Sourcepub fn caret_prefix_snapshot(&self) -> Option<SharedString>
pub fn caret_prefix_snapshot(&self) -> Option<SharedString>
Text before the caret in its editable leaf. Completion engines inspect this plain text, not escaped or reformatted canonical source. Revision/selection-keyed shared native prefix. Repeated query/render reads do not clone a large caret leaf’s bytes.
pub fn caret_prefix(&self) -> Option<&str>
Sourcepub fn capture_suffix(
&self,
len: usize,
) -> Result<CapturedRange, CapturedRangeError>
pub fn capture_suffix( &self, len: usize, ) -> Result<CapturedRange, CapturedRangeError>
Capture a UTF-8 suffix of the caret’s leaf for completion acceptance.
Sourcepub fn capture_leaf_range(
&self,
range: Range<usize>,
) -> Result<CapturedRange, CapturedRangeError>
pub fn capture_leaf_range( &self, range: Range<usize>, ) -> Result<CapturedRange, CapturedRangeError>
Capture an exact UTF-8 range in the caret’s editing leaf. This range is measured in plain leaf text, never canonical Markdown. Useful when a completion token ends before trailing text/newlines in that same leaf.
pub fn is_capture_current(&self, capture: &CapturedRange) -> bool
Sourcepub fn replace_captured(
&mut self,
capture: &mut CapturedRange,
text: &str,
) -> Result<(), CapturedRangeError>
pub fn replace_captured( &mut self, capture: &mut CapturedRange, text: &str, ) -> Result<(), CapturedRangeError>
Replace only a captured range with plain text. One undoable transaction per replacement; does not reparse, apply input rules or submit. Errors leave both the document and capture intact. The caller retains domain ownership (session/window/request) and rejects its own stale callbacks.
Sourcepub fn invalidate_captures(&mut self)
pub fn invalidate_captures(&mut self)
Invalidate outstanding host captures without changing document/source. Hosts call this when the external owner (session/window/request) changes.
pub fn select_end(&mut self) -> Result<(), SelectionError>
Source§impl BlockEditorModel
impl BlockEditorModel
Sourcepub fn selected_cells(&self) -> Option<Vec<Vec<BlockId>>>
pub fn selected_cells(&self) -> Option<Vec<Vec<BlockId>>>
The cells of a BlockSelection::Cells rectangle, row by row.
Sourcepub fn whole_columns_selected(&self) -> bool
pub fn whole_columns_selected(&self) -> bool
Whether the selection is whole column(s): a cell selection over every row of its table.
Sourcepub fn column_align_at_caret(&self) -> Option<ColumnAlign>
pub fn column_align_at_caret(&self) -> Option<ColumnAlign>
The alignment of the column holding the selection head.
Sourcepub fn select_table_line(
&mut self,
table: BlockId,
line: TableLine,
) -> Result<bool, CommandError>
pub fn select_table_line( &mut self, table: BlockId, line: TableLine, ) -> Result<bool, CommandError>
Select a whole row or column of table as BlockSelection::Cells.
Auto Trait Implementations§
impl !Freeze for BlockEditorModel
impl !RefUnwindSafe for BlockEditorModel
impl !Sync for BlockEditorModel
impl !UnwindSafe for BlockEditorModel
impl Send for BlockEditorModel
impl Unpin for BlockEditorModel
impl UnsafeUnpin for BlockEditorModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more