Fix issue #4859: [Bug]: Regression on copy-paste text into the chat prompt input box

This commit is contained in:
openhands 2024-11-09 06:34:40 +00:00
parent 67c8915d51
commit 76a8fdd734

View File

@ -41,17 +41,19 @@ export function ChatInput({
const handlePaste = (event: React.ClipboardEvent<HTMLTextAreaElement>) => {
// Only handle paste if we have an image paste handler and there are files
if (onImagePaste && event.clipboardData.files.length > 0) {
const files = Array.from(event.clipboardData.files).filter((file) =>
file.type.startsWith("image/"),
);
// Only prevent default if we found image files to handle
if (files.length > 0) {
event.preventDefault();
onImagePaste(files);
}
if (!onImagePaste || event.clipboardData.files.length === 0) {
// For text paste, let the default behavior handle it
return;
}
const files = Array.from(event.clipboardData.files).filter((file) =>
file.type.startsWith("image/"),
);
// Only prevent default if we found image files to handle
if (files.length > 0) {
event.preventDefault();
onImagePaste(files);
}
// For text paste, let the default behavior handle it
};
const handleDragOver = (event: React.DragEvent<HTMLTextAreaElement>) => {