pub struct Engine { /* private fields */ }Expand description
Synchronous, storage-neutral editor state machine.
Thread ownership: the host chooses the owning thread and must keep all
mutable access on that thread. Engine does not create threads or invoke
host callbacks.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn with_id_generator(ids: Box<dyn IdGenerator>) -> Self
pub fn with_id_generator(ids: Box<dyn IdGenerator>) -> Self
Construct an empty engine with a host-provided identifier source.
Sourcepub fn open_buffer(&mut self, text: &str) -> BufferId
pub fn open_buffer(&mut self, text: &str) -> BufferId
Open text with a newly generated buffer identifier.
Sourcepub fn load_buffer(
&mut self,
id: BufferId,
text: &str,
revision: Revision,
) -> BufferId
pub fn load_buffer( &mut self, id: BufferId, text: &str, revision: Revision, ) -> BufferId
Load text under a host-provided id and revision.
Sourcepub fn adopt_buffer(&mut self, buffer: Buffer) -> BufferId
pub fn adopt_buffer(&mut self, buffer: Buffer) -> BufferId
Adopt a prepared buffer without performing persistence or I/O.
Sourcepub fn close_buffer(&mut self, id: BufferId) -> Option<Buffer>
pub fn close_buffer(&mut self, id: BufferId) -> Option<Buffer>
Remove a buffer and its transient engine state.
Sourcepub fn snapshot(&self, id: BufferId) -> Option<EngineSnapshot>
pub fn snapshot(&self, id: BufferId) -> Option<EngineSnapshot>
Capture a buffer snapshot.
Sourcepub fn selections(&self, id: BufferId) -> Option<&[Selection]>
pub fn selections(&self, id: BufferId) -> Option<&[Selection]>
Borrow a buffer’s current selections.
Sourcepub fn set_selections(
&mut self,
id: BufferId,
selections: Vec<Selection>,
) -> Result<(), Error>
pub fn set_selections( &mut self, id: BufferId, selections: Vec<Selection>, ) -> Result<(), Error>
Replace and normalize a buffer’s selections.
Sourcepub fn apply_edit(
&mut self,
id: BufferId,
op: EditOp,
timestamp_ms: i64,
) -> Result<ChangeBatch, Error>
pub fn apply_edit( &mut self, id: BufferId, op: EditOp, timestamp_ms: i64, ) -> Result<ChangeBatch, Error>
Apply one raw atomic edit as a discrete undo group.
Sourcepub fn apply_grouped_edit(
&mut self,
id: BufferId,
ops: &[EditOp],
selections_after: Vec<Selection>,
command: &str,
timestamp_ms: i64,
) -> Result<Option<ChangeBatch>, Error>
pub fn apply_grouped_edit( &mut self, id: BufferId, ops: &[EditOp], selections_after: Vec<Selection>, command: &str, timestamp_ms: i64, ) -> Result<Option<ChangeBatch>, Error>
Apply caller-planned operations as one discrete undo group.
Sourcepub fn apply_selection_edit(
&mut self,
id: BufferId,
edit: &SelectionEdit,
timestamp_ms: i64,
) -> Result<Option<ChangeBatch>, Error>
pub fn apply_selection_edit( &mut self, id: BufferId, edit: &SelectionEdit, timestamp_ms: i64, ) -> Result<Option<ChangeBatch>, Error>
Plan and apply a selection-aware edit.
Sourcepub fn undo(
&mut self,
id: BufferId,
timestamp_ms: i64,
) -> Result<Option<ChangeBatch>, Error>
pub fn undo( &mut self, id: BufferId, timestamp_ms: i64, ) -> Result<Option<ChangeBatch>, Error>
Undo the current group.
Sourcepub fn redo(
&mut self,
id: BufferId,
timestamp_ms: i64,
) -> Result<Option<ChangeBatch>, Error>
pub fn redo( &mut self, id: BufferId, timestamp_ms: i64, ) -> Result<Option<ChangeBatch>, Error>
Replay the most-recent redo child.
Sourcepub fn redo_alternate(
&mut self,
id: BufferId,
timestamp_ms: i64,
) -> Result<Option<ChangeBatch>, Error>
pub fn redo_alternate( &mut self, id: BufferId, timestamp_ms: i64, ) -> Result<Option<ChangeBatch>, Error>
Replay an alternate redo branch.
Sourcepub fn replace_text_if_revision(
&mut self,
id: BufferId,
expected: Revision,
text: impl Into<String>,
timestamp_ms: i64,
) -> Result<ChangeBatch, Error>
pub fn replace_text_if_revision( &mut self, id: BufferId, expected: Revision, text: impl Into<String>, timestamp_ms: i64, ) -> Result<ChangeBatch, Error>
Replace the full document only when the caller’s revision is current.
Sourcepub fn reconcile_text_if_revision(
&mut self,
id: BufferId,
expected: Revision,
text: impl Into<String>,
timestamp_ms: i64,
) -> Result<Option<ChangeBatch>, Error>
pub fn reconcile_text_if_revision( &mut self, id: BufferId, expected: Revision, text: impl Into<String>, timestamp_ms: i64, ) -> Result<Option<ChangeBatch>, Error>
Reconcile a full host document when its expected revision is current.
Returns None when the supplied text already matches, so loading or
reconciling current state never emits a phantom edit. A real difference
is applied as the minimal single splice (shared prefix and suffix kept),
so selections and host line mirrors outside the changed range stay put
instead of collapsing to the document end.
Sourcepub fn deltas_since(
&self,
id: BufferId,
since_revision: u64,
) -> (Vec<RopeEditDelta>, bool)
pub fn deltas_since( &self, id: BufferId, since_revision: u64, ) -> (Vec<RopeEditDelta>, bool)
Return byte deltas strictly newer than since_revision.
Sourcepub fn deltas_with_points_since(
&self,
id: BufferId,
since_revision: u64,
) -> (Vec<RopeEditDeltaWithPoints>, bool)
pub fn deltas_with_points_since( &self, id: BufferId, since_revision: u64, ) -> (Vec<RopeEditDeltaWithPoints>, bool)
Return position-augmented deltas strictly newer than since_revision.
Sourcepub fn drain_events(&mut self) -> Vec<EngineEvent>
pub fn drain_events(&mut self) -> Vec<EngineEvent>
Drain events emitted since the previous call.
Sourcepub fn state(&self) -> &EngineState
pub fn state(&self) -> &EngineState
Borrow the lower-level state for native host queries during migration.
Sourcepub fn state_mut(&mut self) -> &mut EngineState
pub fn state_mut(&mut self) -> &mut EngineState
Mutably borrow lower-level state for native host-only metadata changes.