Skip to main content

BlockEditorModel

Struct BlockEditorModel 

Source
pub struct BlockEditorModel { /* private fields */ }
Expand description

Headless editor facade (spike name). Phase 3 wraps this in the BlockEditorState entity.

Implementations§

Source§

impl BlockEditorModel

Source

pub fn insert_text( &mut self, text: &str, origin: EditOrigin, ) -> Result<(), CommandError>

Insert plain text at the selection (replacing it); \n splits blocks.

Source

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

Source

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.

Source

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

Source

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

Source

pub fn run(&mut self, command: EditorCommand) -> Result<bool, CommandError>

Run an EditorCommand; returns whether the document or selection changed.

Source§

impl BlockEditorModel

Source

pub fn from_markdown( source: &str, extensions: MarkdownExtensions, ) -> Result<Self, SharedString>

Parse Markdown into a model.

Source

pub fn set_source(&mut self, source: &str) -> Result<(), SharedString>

Replace the content. Fresh ids (old positions fail with UnknownBlock), history cleared.

Source

pub fn source(&self) -> String

The document as canonical Markdown.

Source

pub fn revision(&self) -> u64

Document revision; bumped by every committed transaction.

Source

pub fn document(&self) -> DocumentRef<'_>

Read-only view of the block tree.

Source

pub fn selection(&self) -> &BlockSelection

The current selection.

Source

pub fn set_selection( &mut self, selection: BlockSelection, ) -> Result<(), SelectionError>

Set the selection after validating it against the document.

Source

pub fn caret(&self) -> Option<BlockPosition>

The caret (head of a text selection); None for a block selection.

Source

pub fn active_marks(&self) -> MarkSet

Marks the next typed text gets (stored marks, else inherited at the caret).

Source

pub fn mark_state(&self, kind: MarkKind) -> MarkState

Whether kind is on, off or mixed over the selection.

Source

pub fn block_kind_at_caret(&self) -> Option<BlockKind>

Kind of the text block holding the caret, if any.

Source

pub fn break_coalescing(&mut self)

End the current typing group, so the next edit is its own undo step.

Source

pub fn can_undo(&self) -> bool

Whether there is something to undo.

Source

pub fn can_redo(&self) -> bool

Whether there is something to redo.

Source

pub fn undo(&mut self) -> bool

Undo one group; returns whether anything changed.

Source

pub fn redo(&mut self) -> bool

Redo one group; returns whether anything changed.

Source§

impl BlockEditorModel

Source

pub fn source_snapshot(&self) -> SourceSnapshot

Source

pub fn capture_caret(&self) -> Result<CapturedRange, CapturedRangeError>

Capture the head/caret, inserting there even when text is selected.

Source

pub fn capture_selection(&self) -> Result<CapturedRange, CapturedRangeError>

Capture the current text selection for one atomic replacement.

Source

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.

Source

pub fn caret_prefix(&self) -> Option<&str>

Source

pub fn capture_suffix( &self, len: usize, ) -> Result<CapturedRange, CapturedRangeError>

Capture a UTF-8 suffix of the caret’s leaf for completion acceptance.

Source

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.

Source

pub fn is_capture_current(&self, capture: &CapturedRange) -> bool

Source

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.

Source

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.

Source

pub fn select_end(&mut self) -> Result<(), SelectionError>

Source§

impl BlockEditorModel

Source

pub fn selected_cells(&self) -> Option<Vec<Vec<BlockId>>>

The cells of a BlockSelection::Cells rectangle, row by row.

Source

pub fn whole_columns_selected(&self) -> bool

Whether the selection is whole column(s): a cell selection over every row of its table.

Source

pub fn column_align_at_caret(&self) -> Option<ColumnAlign>

The alignment of the column holding the selection head.

Source

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§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

Convert 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)

Convert &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)

Convert &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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more