Adding a feature to paste files you ctrl v (#2183)

This commit is contained in:
AbbasSalloum
2025-12-12 06:55:16 -05:00
committed by GitHub
parent 909bc421c0
commit 6d8f083c6f

View File

@@ -532,6 +532,31 @@ export default function MessageInput({
}
};
const handlePaste = (e: React.ClipboardEvent<HTMLTextAreaElement>) => {
const clipboardItems = e.clipboardData?.items;
const files: File[] = [];
if (!clipboardItems) return;
for (let i = 0; i < clipboardItems.length; i++) {
const item = clipboardItems[i];
if (item.kind === 'file') {
const file = item.getAsFile();
if (file) {
files.push(file);
}
}
}
if (files.length > 0) {
// Prevent weird binary stuff from being pasted as text
e.preventDefault();
uploadFiles(files);
}
};
const handlePostDocumentSelect = (doc: any) => {
console.log('Selected document:', doc);
};
@@ -691,6 +716,7 @@ export default function MessageInput({
className="inputbox-style no-scrollbar bg-lotion dark:text-bright-gray dark:placeholder:text-bright-gray/50 w-full overflow-x-hidden overflow-y-auto rounded-t-[23px] px-2 text-base leading-tight whitespace-pre-wrap opacity-100 placeholder:text-gray-500 focus:outline-hidden sm:px-3 dark:bg-transparent"
onInput={handleInput}
onKeyDown={handleKeyDown}
onPaste={handlePaste}
aria-label={t('inputPlaceholder')}
/>
</div>