diff --git a/src/components/ChatInterface.jsx b/src/components/ChatInterface.jsx index d367edc..2039198 100755 --- a/src/components/ChatInterface.jsx +++ b/src/components/ChatInterface.jsx @@ -1985,19 +1985,34 @@ function ChatInterface({ selectedProject, selectedSession, ws, sendMessage, mess const spaceIndex = textAfterAtQuery.indexOf(' '); const textAfterQuery = spaceIndex !== -1 ? textAfterAtQuery.slice(spaceIndex) : ''; - const newInput = textBeforeAt + '@' + file.path + textAfterQuery; + const newInput = textBeforeAt + '@' + file.path + ' ' + textAfterQuery; + const newCursorPos = textBeforeAt.length + 1 + file.path.length + 1; + + // Immediately ensure focus is maintained + if (textareaRef.current && !textareaRef.current.matches(':focus')) { + textareaRef.current.focus(); + } + + // Update input and cursor position setInput(newInput); + setCursorPosition(newCursorPos); + + // Hide dropdown setShowFileDropdown(false); setAtSymbolPosition(-1); - // Focus back to textarea and set cursor position + // Set cursor position synchronously if (textareaRef.current) { - textareaRef.current.focus(); - const newCursorPos = textBeforeAt.length + 1 + file.path.length; - setTimeout(() => { - textareaRef.current.setSelectionRange(newCursorPos, newCursorPos); - setCursorPosition(newCursorPos); - }, 0); + // Use requestAnimationFrame for smoother updates + requestAnimationFrame(() => { + if (textareaRef.current) { + textareaRef.current.setSelectionRange(newCursorPos, newCursorPos); + // Ensure focus is maintained + if (!textareaRef.current.matches(':focus')) { + textareaRef.current.focus(); + } + } + }); } }; @@ -2238,6 +2253,37 @@ function ChatInterface({ selectedProject, selectedSession, ws, sendMessage, mess )} + {/* File dropdown - positioned outside dropzone to avoid conflicts */} + {showFileDropdown && filteredFiles.length > 0 && ( +
+ {filteredFiles.map((file, index) => ( +
{ + // Prevent textarea from losing focus on mobile + e.preventDefault(); + e.stopPropagation(); + }} + onClick={(e) => { + e.preventDefault(); + e.stopPropagation(); + selectFile(file); + }} + > +
{file.name}
+
+ {file.path} +
+
+ ))} +
+ )} +