From cfcedeb616ceb93a4ffdd85ba4536493e55146bc Mon Sep 17 00:00:00 2001 From: Aadesh Kheria Date: Tue, 5 May 2026 13:22:17 -0700 Subject: [PATCH] Refactor applyDashboardPatches to use 'draft' instead of 'running' for improved clarity and maintainability --- .../src/components/vibe-coding/chat-adapters.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/dashboard/src/components/vibe-coding/chat-adapters.ts b/apps/dashboard/src/components/vibe-coding/chat-adapters.ts index a98e8d662..4746637d8 100644 --- a/apps/dashboard/src/components/vibe-coding/chat-adapters.ts +++ b/apps/dashboard/src/components/vibe-coding/chat-adapters.ts @@ -75,7 +75,7 @@ export type DashboardPatchSnapshot = { }; export function applyDashboardPatches(source: string, edits: DashboardPatchEdit[]): DashboardPatchResult { - let running = source; + let draft = source; let applied = 0; const failures: DashboardPatchFailure[] = []; @@ -84,8 +84,8 @@ export function applyDashboardPatches(source: string, edits: DashboardPatchEdit[ const matches: number[] = []; let from = 0; - while (from <= running.length) { - const at = running.indexOf(edit.oldText, from); + while (from <= draft.length) { + const at = draft.indexOf(edit.oldText, from); if (at === -1) break; matches.push(at); from = at + Math.max(edit.oldText.length, 1); @@ -114,11 +114,14 @@ export function applyDashboardPatches(source: string, edits: DashboardPatchEdit[ chosenIndex = matches[0]; } - running = running.slice(0, chosenIndex) + edit.newText + running.slice(chosenIndex + edit.oldText.length); + draft = draft.slice(0, chosenIndex) + edit.newText + draft.slice(chosenIndex + edit.oldText.length); applied += 1; }); - return { updatedSource: running, applied, failures }; + if (failures.length > 0) { + return { updatedSource: source, applied: 0, failures }; + } + return { updatedSource: draft, applied, failures }; } function parsePatchEdits(args: unknown): DashboardPatchEdit[] | null {