| 235 | * @returns Object with the new input text and cursor position |
| 236 | */ |
| 237 | export function applyDirectorySuggestion(input: string, suggestionId: string, tokenStartPos: number, tokenLength: number, isDirectory: boolean): { |
| 238 | newInput: string; |
| 239 | cursorPos: number; |
| 240 | } { |
| 241 | const suffix = isDirectory ? '/' : ' '; |
| 242 | const before = input.slice(0, tokenStartPos); |
| 243 | const after = input.slice(tokenStartPos + tokenLength); |
| 244 | // Always add @ prefix - if token already has it, we're replacing |
| 245 | // the whole token (including @) with @suggestion.id |
| 246 | const replacement = '@' + suggestionId + suffix; |
| 247 | const newInput = before + replacement + after; |
| 248 | return { |
| 249 | newInput, |
| 250 | cursorPos: before.length + replacement.length |
| 251 | }; |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Extract a completable token at the cursor position |