From 985de024044312c72d04d4107c47db62a5b7fd95 Mon Sep 17 00:00:00 2001 From: Vivek R <123vivekr@gmail.com> Date: Sun, 6 Jul 2025 16:52:11 +0530 Subject: [PATCH] fix: correct file mention replacement in FloatingPromptInput - Fix handleFileSelect to properly find @ position instead of assuming cursorPosition-1 - Replace entire @query text with selected file path instead of appending - Add error handling for edge cases where @ symbol cannot be found - Resolves issue where typing @READ and selecting README.md resulted in @READ@README.md Fixes #114 --- src/components/FloatingPromptInput.tsx | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/components/FloatingPromptInput.tsx b/src/components/FloatingPromptInput.tsx index ec4e880..a675275 100644 --- a/src/components/FloatingPromptInput.tsx +++ b/src/components/FloatingPromptInput.tsx @@ -439,10 +439,29 @@ const FloatingPromptInputInner = ( const handleFileSelect = (entry: FileEntry) => { if (textareaRef.current) { + // Find the @ position before cursor + let atPosition = -1; + for (let i = cursorPosition - 1; i >= 0; i--) { + if (prompt[i] === '@') { + atPosition = i; + break; + } + // Stop if we hit whitespace (new word) + if (prompt[i] === ' ' || prompt[i] === '\n') { + break; + } + } + + if (atPosition === -1) { + // @ not found, this shouldn't happen but handle gracefully + console.error('[FloatingPromptInput] @ position not found'); + return; + } + // Replace the @ and partial query with the selected path (file or directory) const textarea = textareaRef.current; - const beforeAt = prompt.substring(0, cursorPosition - 1); - const afterCursor = prompt.substring(cursorPosition + filePickerQuery.length); + const beforeAt = prompt.substring(0, atPosition); + const afterCursor = prompt.substring(cursorPosition); const relativePath = entry.path.startsWith(projectPath || '') ? entry.path.slice((projectPath || '').length + 1) : entry.path;