apply_edits


Description:

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

Apply multiple edits to the buffer efficiently using GTK buffer operations.

Uses GTK TextBuffer's text manipulation for efficient chunk editing. Applies edits in reverse order (from end to start) to preserve line numbers.

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. Sync buffer to file (creates backup, writes, 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