| 787 | * Apply a file suggestion to the input |
| 788 | */ |
| 789 | export 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 | } |