MCPcopy Create free account
hub / github.com/backnotprop/plannotator / applyEdits

Function applyEdits

apps/opencode-plugin/plan-edits.ts:31–49  ·  view source on GitHub ↗
(existingLines: string[], edits: PlanEdit[])

Source from the content-addressed store, hash-verified

29 * state BEFORE any edits in this batch (offsets are adjusted internally)
30 */
31export function applyEdits(existingLines: string[], edits: PlanEdit[]): string[] {
32 const sorted = [...edits].sort((a, b) => a.start - b.start);
33 const lines = [...existingLines];
34 let offset = 0;
35
36 for (const edit of sorted) {
37 const start = edit.start - 1 + offset;
38 const end = edit.end != null
39 ? edit.end + offset
40 : lines.length;
41
42 const newLines = edit.content ? edit.content.split("\n") : [];
43 const removedCount = end - start;
44 lines.splice(start, removedCount, ...newLines);
45 offset += newLines.length - removedCount;
46 }
47
48 return lines;
49}
50
51/**
52 * Validate a batch of edits against the current file state.

Callers 2

executeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected