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

Function editPromptInEditor

src/utils/promptEditor.ts:138–188  ·  view source on GitHub ↗
(
  currentPrompt: string,
  pastedContents?: Record<number, PastedContent>,
)

Source from the content-addressed store, hash-verified

136
137// sync IO: called from sync context (React components, sync command handlers)
138export function editPromptInEditor(
139 currentPrompt: string,
140 pastedContents?: Record<number, PastedContent>,
141): EditorResult {
142 const fs = getFsImplementation()
143 const tempFile = generateTempFilePath()
144
145 try {
146 // Expand any pasted text references before editing
147 const expandedPrompt = pastedContents
148 ? expandPastedTextRefs(currentPrompt, pastedContents)
149 : currentPrompt
150
151 // Write expanded prompt to temp file
152 writeFileSync_DEPRECATED(tempFile, expandedPrompt, {
153 encoding: 'utf-8',
154 flush: true,
155 })
156
157 // Delegate to editFileInEditor
158 const result = editFileInEditor(tempFile)
159
160 if (result.content === null) {
161 return result
162 }
163
164 // Trim a single trailing newline if present (common editor behavior)
165 let finalContent = result.content
166 if (finalContent.endsWith('\n') && !finalContent.endsWith('\n\n')) {
167 finalContent = finalContent.slice(0, -1)
168 }
169
170 // Re-collapse pasted content if it wasn't edited
171 if (pastedContents) {
172 finalContent = recollapsePastedContent(
173 finalContent,
174 currentPrompt,
175 pastedContents,
176 )
177 }
178
179 return { content: finalContent }
180 } finally {
181 // Clean up temp file
182 try {
183 fs.unlinkSync(tempFile)
184 } catch {
185 // Ignore cleanup errors
186 }
187 }
188}
189

Callers 7

QuestionViewFunction · 0.85
PreviewQuestionViewFunction · 0.85
handleKeyDownFunction · 0.85
PromptInputFunction · 0.85
PromptStepFunction · 0.85
DescriptionStepFunction · 0.85
GenerateStepFunction · 0.85

Calls 6

getFsImplementationFunction · 0.85
generateTempFilePathFunction · 0.85
expandPastedTextRefsFunction · 0.85
writeFileSync_DEPRECATEDFunction · 0.85
editFileInEditorFunction · 0.85
recollapsePastedContentFunction · 0.85

Tested by

no test coverage detected