SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.
JavaScript a2aagentic-aiai-agentsdevtoolsmcp-clientn8n-alternativeno-codeopen-sourceorchestrationsmythosvisual-builder
Enhance paste handling in ChatInput component
Salman-Ahamedd7a0d6e798d4
diff --git a/packages/app/src/react/features/ai-chat/components/input.tsx b/packages/app/src/react/features/ai-chat/components/input.tsxindex 7ac9980d..cda5e3b4 100644--- a/packages/app/src/react/features/ai-chat/components/input.tsx+++ b/packages/app/src/react/features/ai-chat/components/input.tsx@@ -164,23 +164,52 @@ export const ChatInput = forwardRef<ChatInputRef, ChatInputProps>(}}, []);- const handlePaste = (e: ClipboardEvent<HTMLTextAreaElement>) => {- e.preventDefault();- const pasted = e.clipboardData.getData('text/plain');+ /**+ * Professional paste handler that mimics default browser behavior+ * with additional large text file attachment feature+ */+ const handlePaste = useCallback(+ (e: ClipboardEvent<HTMLTextAreaElement>) => {+ // Get pasted text first+ const pastedText = e.clipboardData?.getData('text/plain') || '';- if (pasted.length >= LARGE_TEXT_THRESHOLD) {- const file = createFileFromText(pasted);- handleFileDrop([file.file]);- setMessage('');- } else setMessage(pasted);- setTimeout(() => {- if (inputRef.current) {- inputRef.current.scrollTop = inputRef.current.scrollHeight;- inputRef.current.selectionStart = inputRef.current.selectionEnd =- pasted.length >= LARGE_TEXT_THRESHOLD ? 0 : pasted.length;+ // Check if it's large text that should become a file attachment+ if (pastedText.length >= LARGE_TEXT_THRESHOLD) {+ e.preventDefault();++ try {+ const file = createFileFromText(pastedText);+ handleFileDrop([file.file]);+ // Don't clear the message - keep existing content+ // The pasted text will be handled as file attachment++ // Focus and maintain cursor position after file creation+ requestAnimationFrame(() => {+ const textarea = inputRef.current;+ if (textarea) {+ textarea.focus();+ // Keep cursor at current position, don't reset to 0+ const currentPos = textarea.selectionStart || 0;+ textarea.selectionStart = currentPos;+ textarea.selectionEnd = currentPos;+ }+ });+ } catch {+ // Fallback: let browser handle it normally if file creation fails+ return;+ }+ } else {+ // For normal text, let the browser handle it naturally+ // This preserves all default browser behavior including:+ // - Natural cursor positioning+ // - Text selection replacement+ // - Undo/redo support+ // - Native textarea behavior+ return;}- }, 0);- };+ },+ [handleFileDrop],+ );const isMaxLengthReached = message.length === maxLength;const canSubmit =