Skip to content

Lens.transaction() - Atomic batch edits #4

@williamsharkey

Description

@williamsharkey

Feature Request

Add Lens.transaction() for atomic batch edits that commit or rollback together.

Use Case

When making multi-line changes, if the connection drops mid-edit, the file can be left in a partial state. Transactions would ensure all-or-nothing.

Proposed API

// Option 1: Callback style
Lens.transaction(() => {
  Lens.setLine(10, 'new code');
  Lens.insertLine(11, 'more code');
  Lens.deleteLine(20);
}); // All changes applied atomically

// Option 2: Explicit commit
const tx = Lens.begin();
tx.setLine(10, 'new code');
tx.insertLine(11, 'more code');
tx.commit(); // or tx.rollback()

Implementation Notes

  • Buffer changes in memory
  • Apply all at once on commit
  • Track original content for rollback
  • Could integrate with undo/redo stack

Priority

Medium - workaround exists (careful single edits), but would improve reliability for complex refactors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions