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

Function applyFileSuggestion

src/hooks/fileSuggestions.ts:860–882  ·  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

858 * Apply a file suggestion to the input
859 */
860export function applyFileSuggestion(
861 suggestion: string | SuggestionItem,
862 input: string,
863 partialPath: string,
864 startPos: number,
865 onInputChange: (value: string) => void,
866 setCursorOffset: (offset: number) => void,
867): void {
868 // Extract suggestion text from string or SuggestionItem
869 const suggestionText =
870 typeof suggestion === 'string' ? suggestion : suggestion.displayText
871
872 // Replace the partial path with the selected file path
873 const newInput =
874 input.substring(0, startPos) +
875 suggestionText +
876 input.substring(startPos + partialPath.length)
877 onInputChange(newInput)
878
879 // Move cursor to end of the file path
880 const newCursorPos = startPos + suggestionText.length
881 setCursorOffset(newCursorPos)
882}

Callers 1

useTypeaheadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected