MCPcopy Index your code
hub / github.com/codeaashu/claude-code / recollapsePastedContent

Function recollapsePastedContent

src/utils/promptEditor.ts:107–135  ·  view source on GitHub ↗

* Re-collapse expanded pasted text by finding content that matches * pastedContents and replacing it with references.

(
  editedPrompt: string,
  originalPrompt: string,
  pastedContents: Record<number, PastedContent>,
)

Source from the content-addressed store, hash-verified

105 * pastedContents and replacing it with references.
106 */
107function 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)
138export function editPromptInEditor(

Callers 1

editPromptInEditorFunction · 0.85

Calls 3

getPastedTextRefNumLinesFunction · 0.85
formatPastedTextRefFunction · 0.85
entriesMethod · 0.80

Tested by

no test coverage detected