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

Function applyCommandSuggestion

src/utils/suggestions/commandSuggestions.ts:503–539  ·  view source on GitHub ↗
(
  suggestion: string | SuggestionItem,
  shouldExecute: boolean,
  commands: Command[],
  onInputChange: (value: string) => void,
  setCursorOffset: (offset: number) => void,
  onSubmit: (value: string, isSubmittingSlashCommand?: boolean) => void,
)

Source from the content-addressed store, hash-verified

501 * Apply selected command to input
502 */
503export function applyCommandSuggestion(
504 suggestion: string | SuggestionItem,
505 shouldExecute: boolean,
506 commands: Command[],
507 onInputChange: (value: string) => void,
508 setCursorOffset: (offset: number) => void,
509 onSubmit: (value: string, isSubmittingSlashCommand?: boolean) => void,
510): void {
511 // Extract command name and object from string or SuggestionItem metadata
512 let commandName: string
513 let commandObj: Command | undefined
514 if (typeof suggestion === 'string') {
515 commandName = suggestion
516 commandObj = shouldExecute ? getCommand(commandName, commands) : undefined
517 } else {
518 if (!isCommandMetadata(suggestion.metadata)) {
519 return // Invalid suggestion, nothing to apply
520 }
521 commandName = getCommandName(suggestion.metadata)
522 commandObj = suggestion.metadata
523 }
524
525 // Format the command input with trailing space
526 const newInput = formatCommand(commandName)
527 onInputChange(newInput)
528 setCursorOffset(newInput.length)
529
530 // Execute command if requested and it takes no arguments
531 if (shouldExecute && commandObj) {
532 if (
533 commandObj.type !== 'prompt' ||
534 (commandObj.argNames ?? []).length === 0
535 ) {
536 onSubmit(newInput, /* isSubmittingSlashCommand */ true)
537 }
538 }
539}
540
541// Helper function at bottom of file per CLAUDE.md
542function cleanWord(word: string) {

Callers 1

useTypeaheadFunction · 0.85

Calls 5

getCommandFunction · 0.85
isCommandMetadataFunction · 0.85
formatCommandFunction · 0.85
onSubmitFunction · 0.85
getCommandNameFunction · 0.50

Tested by

no test coverage detected