Skip to main content

Crate termesh_editor

Crate termesh_editor 

Source
Expand description

The editor core and the shared-state transaction spine (ARCHITECTURE.md §8).

Both the human and the agent change buffers, so there is exactly one edit path: every change is an EditTransaction stamped with the buffer version it was authored against. That yields one undo history, clean LSP/syntax sync, and — the reason it matters — safe agent diff-review: an agent proposal is a ChangeSet against base_version; on accept we apply directly if the buffer is still there, or carry it forward through the intervening edits. Modeled on Helix / CodeMirror 6.

The design decisions behind this module — including what “carries forward cleanly” actually means, case by case — are in ADR-0006.

use termesh_editor::{Assoc, ChangeSet};
use ropey::Rope;

let original = Rope::from_str("fn main() {}");
// An agent proposes renaming `main`, anchored at char 3.
let proposal = ChangeSet::replace(original.len_chars(), 3, 7, "run");

// Meanwhile the human types at the start of the line.
let human = ChangeSet::replace(original.len_chars(), 0, 0, "pub ");
let current = human.apply(&original);

// The proposal's anchor rides forward over the human's edit instead of going stale.
assert_eq!(human.map_pos(3, Assoc::After), 7);
assert_eq!(current.to_string(), "pub fn main() {}");

Re-exports§

pub use buffer::Buffer;
pub use buffer::EditError;
pub use buffer::EditResult;
pub use buffer::LineEnding;
pub use change::Assoc;
pub use change::ChangeSet;
pub use change::ChangeSetBuilder;
pub use change::ChangedSpan;
pub use change::Operation;
pub use change::RangeEffect;
pub use decoration::Decoration;
pub use decoration::DecorationClass;
pub use decoration::DecorationSet;
pub use decoration::HunkSide;
pub use decoration::LineDecoration;
pub use decoration::Severity;
pub use decoration::SyntaxKind;
pub use history::History;
pub use search::find_all;
pub use search::CaseMode;
pub use search::Match;
pub use selection::Range;
pub use selection::Selection;
pub use transaction::EditSource;
pub use transaction::EditTransaction;
pub use transaction::UndoGroupId;
pub use transaction::Version;

Modules§

buffer
Buffer — a rope-backed document and the only thing that applies transactions.
change
ChangeSet — the position-composable change representation (ADR-0006 §1).
decoration
Styled overlays on buffer text (ARCHITECTURE.md §10).
history
Undo/redo over the transaction log (ADR-0006 §6).
movement
Cursor motion over a rope. Pure functions on (text, position), so every rule here is testable without constructing a crate::Buffer.
position
Char offsets in, protocol positions out.
search
Finding text in a buffer. Pure functions over a rope, in char offsets.
selection
Cursors and selections, and how they survive somebody else’s edit.
transaction
EditTransaction — the one and only way a buffer changes (ARCHITECTURE.md §8).

Enums§

ConflictReason
Why a proposal hunk could not be carried forward onto the current buffer.
HunkState
Whether a proposal hunk can still be applied (ADR-0006 §4, §5).