| 858 | * Apply a file suggestion to the input |
| 859 | */ |
| 860 | export 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 | } |