| 176 | * Apply a shell completion suggestion by replacing the current word |
| 177 | */ |
| 178 | export function applyShellSuggestion(suggestion: SuggestionItem, input: string, cursorOffset: number, onInputChange: (value: string) => void, setCursorOffset: (offset: number) => void, completionType: ShellCompletionType | undefined): void { |
| 179 | const beforeCursor = input.slice(0, cursorOffset); |
| 180 | const lastSpaceIndex = beforeCursor.lastIndexOf(' '); |
| 181 | const wordStart = lastSpaceIndex + 1; |
| 182 | |
| 183 | // Prepare the replacement text based on completion type |
| 184 | let replacementText: string; |
| 185 | if (completionType === 'variable') { |
| 186 | replacementText = '$' + suggestion.displayText + ' '; |
| 187 | } else if (completionType === 'command') { |
| 188 | replacementText = suggestion.displayText + ' '; |
| 189 | } else { |
| 190 | replacementText = suggestion.displayText; |
| 191 | } |
| 192 | const newInput = input.slice(0, wordStart) + replacementText + input.slice(cursorOffset); |
| 193 | onInputChange(newInput); |
| 194 | setCursorOffset(wordStart + replacementText.length); |
| 195 | } |
| 196 | const DM_MEMBER_RE = /(^|\s)@[\w-]*$/; |
| 197 | function applyTriggerSuggestion(suggestion: SuggestionItem, input: string, cursorOffset: number, triggerRe: RegExp, onInputChange: (value: string) => void, setCursorOffset: (offset: number) => void): void { |
| 198 | const m = input.slice(0, cursorOffset).match(triggerRe); |