Skip to main content

apply_buffer_edit

Function apply_buffer_edit 

Source
pub fn apply_buffer_edit(buf: &mut View, edit: Edit) -> Edit
Expand description

Apply a hjkl_buffer::Edit and return the inverse for undo.

0.0.42 (Patch C-δ.7): the apply_edit reach is intentionally kept against the concrete &mut hjkl_buffer::View rather than lifted onto a trait method. Rationale:

  • hjkl_buffer::Edit is the rich buffer-side enum (~8 variants — InsertChar, InsertStr, DeleteRange, JoinLines, SplitLines, Replace, InsertBlock, DeleteBlockChunks) with ~700 LOC of do_* machinery in hjkl-buffer. Lifting it onto BufferEdit would require either an associated Edit type (forces every backend to design its own rich-edit enum just to compile) or duplicating the 8 variants on the trait surface (busts the discipline cap).
  • crate::types::Edit is a separate value type (Range<Pos> + String replacement) used by the change-log emitter; it’s intentionally simpler and lossy for block / join / split ops.

Centralizing the reach in this free fn keeps Editor::mutate_edit trait-shaped at the call site (no self.buffer.<inherent> hop in the editor body) and gives 0.1.0 a single seam to flip when the B: View generic lands.

The 0.1.0 design will introduce BufferEdit::apply_edit(&mut self, op: Self::Edit) -> Self::Edit with type Edit; so backends pick their own edit enum. This free fn forwards there once that lands.