apply_edits


Description:

public async void apply_edits (ArrayList<FileChange> changes) throws Error

Apply multiple edits to the buffer efficiently using in-memory lines array.

Applies edits in reverse order (from end to start) to preserve line numbers. Works with in-memory lines array for efficient manipulation.

Process

  1. Ensure buffer is loaded (calls read_async() if needed)

    2. Apply changes in reverse order (from end to start) to preserve line numbers

    3. For each change: calls apply_edit()

    4. Join lines back into content string

    5. Write to file (backup, write, updates metadata)

FileChange Format

  • Line numbers are 1-based (inclusive start, exclusive end)
  • start == end indicates insertion
  • start != end indicates replacement

Important

Changes must be sorted descending by start line before calling.

Parameters:

changes

List of FileChange objects to apply (must be sorted descending by start)

Exceptions:

Error

if edits cannot be applied