MCPcopy Create free account
hub / github.com/freecodexyz/free-code / applyShellSuggestion

Function applyShellSuggestion

src/hooks/useTypeahead.tsx:178–195  ·  view source on GitHub ↗
(suggestion: SuggestionItem, input: string, cursorOffset: number, onInputChange: (value: string) => void, setCursorOffset: (offset: number) => void, completionType: ShellCompletionType | undefined)

Source from the content-addressed store, hash-verified

176 * Apply a shell completion suggestion by replacing the current word
177 */
178export 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}
196const DM_MEMBER_RE = /(^|\s)@[\w-]*$/;
197function 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);

Callers 1

useTypeaheadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected