( currentContent: string | null, oldString: string, newString: string, isNewFile: boolean, )
| 31 | import { IDEConnectionStatus } from '../ide/ide-client.js'; |
| 32 | |
| 33 | export function applyReplacement( |
| 34 | currentContent: string | null, |
| 35 | oldString: string, |
| 36 | newString: string, |
| 37 | isNewFile: boolean, |
| 38 | ): string { |
| 39 | if (isNewFile) { |
| 40 | return newString; |
| 41 | } |
| 42 | if (currentContent === null) { |
| 43 | // Should not happen if not a new file, but defensively return empty or newString if oldString is also empty |
| 44 | return oldString === '' ? newString : ''; |
| 45 | } |
| 46 | // If oldString is empty and it's not a new file, do not modify the content. |
| 47 | if (oldString === '' && !isNewFile) { |
| 48 | return currentContent; |
| 49 | } |
| 50 | return currentContent.replaceAll(oldString, newString); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Parameters for the Edit tool |
no outgoing calls
no test coverage detected