π OpenHands: AI-Driven Development
feat(frontend): keyboard shortcuts for file copy and paste (#11096)
Hiep Le009567243959
diff --git a/frontend/src/hooks/chat/use-chat-input-events.ts b/frontend/src/hooks/chat/use-chat-input-events.tsindex 294977cc5f..65ce4ff721 100644--- a/frontend/src/hooks/chat/use-chat-input-events.ts+++ b/frontend/src/hooks/chat/use-chat-input-events.ts@@ -30,19 +30,33 @@ export const useChatInputEvents = (ensureCursorVisible(chatInputRef.current);}, [smartResize, chatInputRef]);- // Handle paste events to clean up formatting+ // Handle paste events to clean up formatting and handle filesconst handlePaste = useCallback((e: React.ClipboardEvent) => {e.preventDefault();- // Get plain text from clipboard- const text = e.clipboardData.getData("text/plain");+ // Check if there are files in the clipboard+ const files = Array.from(e.clipboardData.files);+ const hasFiles = files.length > 0;- // Insert plain text- document.execCommand("insertText", false, text);+ if (hasFiles) {+ // Handle file paste - let the file handling system process the files+ // We'll trigger a custom event that the file handling system can listen to+ const customEvent = new CustomEvent("pasteFiles", {+ detail: { files },+ });+ document.dispatchEvent(customEvent);+ return;+ }- // Trigger resize- setTimeout(smartResize, 0);+ // Handle text paste as before+ const text = e.clipboardData.getData("text/plain");+ if (text) {+ // Insert plain text+ document.execCommand("insertText", false, text);+ // Trigger resize+ setTimeout(smartResize, 0);+ }},[smartResize],);diff --git a/frontend/src/hooks/chat/use-file-handling.ts b/frontend/src/hooks/chat/use-file-handling.tsindex 1669df429d..0e0c134810 100644--- a/frontend/src/hooks/chat/use-file-handling.ts+++ b/frontend/src/hooks/chat/use-file-handling.ts@@ -1,4 +1,4 @@-import React, { useRef, useCallback, useState } from "react";+import React, { useRef, useCallback, useState, useEffect } from "react";interface UseFileHandlingReturn {fileInputRef: React.RefObject<HTMLInputElement | null>;@@ -31,6 +31,25 @@ export const useFileHandling = ([onFilesPaste],);+ // Listen for paste events with files+ useEffect(() => {+ const handlePasteFiles = (event: CustomEvent) => {+ const files = event.detail.files as File[];+ if (files && files.length > 0) {+ addFiles(files);+ }+ };++ document.addEventListener("pasteFiles", handlePasteFiles as EventListener);++ return () => {+ document.removeEventListener(+ "pasteFiles",+ handlePasteFiles as EventListener,+ );+ };+ }, [addFiles]);+// File icon click handlerconst handleFileIconClick = useCallback((isDisabled: boolean) => {if (!isDisabled && fileInputRef.current) {