MCPcopy
hub / github.com/codeaashu/claude-code / expandPastedTextRefs

Function expandPastedTextRefs

src/history.ts:81–100  ·  view source on GitHub ↗
(
  input: string,
  pastedContents: Record<number, PastedContent>,
)

Source from the content-addressed store, hash-verified

79 * Image refs are left alone — they become content blocks, not inlined text.
80 */
81export function expandPastedTextRefs(
82 input: string,
83 pastedContents: Record<number, PastedContent>,
84): string {
85 const refs = parseReferences(input)
86 let expanded = input
87 // Splice at the original match offsets so placeholder-like strings inside
88 // pasted content are never confused for real refs. Reverse order keeps
89 // earlier offsets valid after later replacements.
90 for (let i = refs.length - 1; i >= 0; i--) {
91 const ref = refs[i]!
92 const content = pastedContents[ref.id]
93 if (content?.type !== 'text') continue
94 expanded =
95 expanded.slice(0, ref.index) +
96 content.content +
97 expanded.slice(ref.index + ref.match.length)
98 }
99 return expanded
100}
101
102function deserializeLogEntry(line: string): LogEntry {
103 return jsonParse(line) as LogEntry

Callers 3

handlePromptSubmitFunction · 0.85
editPromptInEditorFunction · 0.85
REPLFunction · 0.85

Calls 1

parseReferencesFunction · 0.85

Tested by

no test coverage detected