MCPcopy Create free account
hub / github.com/freecodexyz/free-code / applyFileSuggestion

Function applyFileSuggestion

src/hooks/fileSuggestions.ts:789–811  ·  view source on GitHub ↗
(
  suggestion: string | SuggestionItem,
  input: string,
  partialPath: string,
  startPos: number,
  onInputChange: (value: string) => void,
  setCursorOffset: (offset: number) => void,
)

Source from the content-addressed store, hash-verified

787 * Apply a file suggestion to the input
788 */
789export function applyFileSuggestion(
790 suggestion: string | SuggestionItem,
791 input: string,
792 partialPath: string,
793 startPos: number,
794 onInputChange: (value: string) => void,
795 setCursorOffset: (offset: number) => void,
796): void {
797 // Extract suggestion text from string or SuggestionItem
798 const suggestionText =
799 typeof suggestion === 'string' ? suggestion : suggestion.displayText
800
801 // Replace the partial path with the selected file path
802 const newInput =
803 input.substring(0, startPos) +
804 suggestionText +
805 input.substring(startPos + partialPath.length)
806 onInputChange(newInput)
807
808 // Move cursor to end of the file path
809 const newCursorPos = startPos + suggestionText.length
810 setCursorOffset(newCursorPos)
811}

Callers 1

useTypeaheadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected