MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / popAllEditable

Function popAllEditable

src/utils/messageQueueManager.ts:430–486  ·  view source on GitHub ↗
(
  currentInput: string,
  currentCursorOffset: number,
)

Source from the content-addressed store, hash-verified

428 * Returns undefined if no editable commands in queue.
429 */
430export function popAllEditable(
431 currentInput: string,
432 currentCursorOffset: number,
433): PopAllEditableResult | undefined {
434 if (commandQueue.length === 0) {
435 return undefined
436 }
437
438 const { editable = [], nonEditable = [] } = objectGroupBy(
439 [...commandQueue],
440 cmd => (isQueuedCommandEditable(cmd) ? 'editable' : 'nonEditable'),
441 )
442
443 if (editable.length === 0) {
444 return undefined
445 }
446
447 // Extract text from queued commands (handles both strings and ContentBlockParam[])
448 const queuedTexts = editable.map(cmd => extractTextFromValue(cmd.value))
449 const newInput = [...queuedTexts, currentInput].filter(Boolean).join('\n')
450
451 // Calculate cursor offset: length of joined queued commands + 1 + current cursor offset
452 const cursorOffset = queuedTexts.join('\n').length + 1 + currentCursorOffset
453
454 // Extract images from queued commands
455 const images: PastedContent[] = []
456 let nextImageId = Date.now() // Use timestamp as base for unique IDs
457 for (const cmd of editable) {
458 // handlePromptSubmit queues images in pastedContents (value is a string).
459 // Preserve the original PastedContent id so imageStore lookups still work.
460 if (cmd.pastedContents) {
461 for (const content of Object.values(cmd.pastedContents)) {
462 if (content.type === 'image') {
463 images.push(content)
464 }
465 }
466 }
467 // Bridge/remote commands may embed images directly in ContentBlockParam[].
468 const cmdImages = extractImagesFromValue(cmd.value, nextImageId)
469 images.push(...cmdImages)
470 nextImageId += cmdImages.length
471 }
472
473 for (const command of editable) {
474 logOperation(
475 'popAll',
476 typeof command.value === 'string' ? command.value : undefined,
477 )
478 }
479
480 // Replace queue contents with only the non-editable commands
481 commandQueue.length = 0
482 commandQueue.push(...nonEditable)
483 notifySubscribers()
484
485 return { text: newInput, cursorOffset, images }
486}
487

Callers 2

PromptInputFunction · 0.85
REPLFunction · 0.85

Calls 8

objectGroupByFunction · 0.85
isQueuedCommandEditableFunction · 0.85
extractTextFromValueFunction · 0.85
extractImagesFromValueFunction · 0.85
logOperationFunction · 0.85
notifySubscribersFunction · 0.85
nowMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected