* Re-collapse expanded pasted text by finding content that matches * pastedContents and replacing it with references.
( editedPrompt: string, originalPrompt: string, pastedContents: Record<number, PastedContent>, )
| 105 | * pastedContents and replacing it with references. |
| 106 | */ |
| 107 | function recollapsePastedContent( |
| 108 | editedPrompt: string, |
| 109 | originalPrompt: string, |
| 110 | pastedContents: Record<number, PastedContent>, |
| 111 | ): string { |
| 112 | let collapsed = editedPrompt |
| 113 | |
| 114 | // Find pasted content in the edited text and re-collapse it |
| 115 | for (const [id, content] of Object.entries(pastedContents)) { |
| 116 | if (content.type === 'text') { |
| 117 | const pasteId = parseInt(id) |
| 118 | const contentStr = content.content |
| 119 | |
| 120 | // Check if this exact content exists in the edited prompt |
| 121 | const contentIndex = collapsed.indexOf(contentStr) |
| 122 | if (contentIndex !== -1) { |
| 123 | // Replace with reference |
| 124 | const numLines = getPastedTextRefNumLines(contentStr) |
| 125 | const ref = formatPastedTextRef(pasteId, numLines) |
| 126 | collapsed = |
| 127 | collapsed.slice(0, contentIndex) + |
| 128 | ref + |
| 129 | collapsed.slice(contentIndex + contentStr.length) |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | return collapsed |
| 135 | } |
| 136 | |
| 137 | // sync IO: called from sync context (React components, sync command handlers) |
| 138 | export function editPromptInEditor( |
no test coverage detected