From 74ec82301779577955cb7ad6349e4e9a7846a81d Mon Sep 17 00:00:00 2001 From: nomaven Date: Thu, 1 May 2025 01:50:43 +0400 Subject: [PATCH] Enhances visual feedback during drag-and-drop with dashed outline and transition effects. (#3184) * Add drag-and-drop functionality to ChatTextArea component - Introduced state management for drag feedback with `isDraggingOver`. - Implemented drag event handlers: `handleDragEnter`, `handleDragLeave`, and updated `onDragOver`. - Enhanced visual feedback during drag-and-drop with dashed outline and transition effects. - Reset drag state on drop event. * New Ast salvage * shift to drag * shift to drag * shift to drag * shift to drag * shift to drag * shift to drag * quote * quote * 500ms -> 100ms * updated language and 250ms delay sweetspot * better transitions --------- Co-authored-by: Cline Evaluation --- .changeset/fair-papayas-learn.md | 5 + .../src/components/chat/ChatTextArea.tsx | 360 ++++++++++++++---- 2 files changed, 284 insertions(+), 81 deletions(-) create mode 100644 .changeset/fair-papayas-learn.md diff --git a/.changeset/fair-papayas-learn.md b/.changeset/fair-papayas-learn.md new file mode 100644 index 00000000..5f5c82ff --- /dev/null +++ b/.changeset/fair-papayas-learn.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Minor UX improvement to drag and drop ux diff --git a/webview-ui/src/components/chat/ChatTextArea.tsx b/webview-ui/src/components/chat/ChatTextArea.tsx index bb21d79d..536f3caa 100644 --- a/webview-ui/src/components/chat/ChatTextArea.tsx +++ b/webview-ui/src/components/chat/ChatTextArea.tsx @@ -237,6 +237,7 @@ const ChatTextArea = forwardRef( ) => { const { filePaths, chatSettings, apiConfiguration, openRouterModels, platform } = useExtensionState() const [isTextAreaFocused, setIsTextAreaFocused] = useState(false) + const [isDraggingOver, setIsDraggingOver] = useState(false) const [gitCommits, setGitCommits] = useState([]) const [showSlashCommandsMenu, setShowSlashCommandsMenu] = useState(false) @@ -266,6 +267,10 @@ const ChatTextArea = forwardRef( const [menuPosition, setMenuPosition] = useState(0) const [shownTooltipMode, setShownTooltipMode] = useState(null) const [pendingInsertions, setPendingInsertions] = useState([]) + const [showShiftDragTip, setShowShiftDragTip] = useState(false) + const shiftHoldTimerRef = useRef(null) + const [showUnsupportedFileError, setShowUnsupportedFileError] = useState(false) + const unsupportedFileTimerRef = useRef(null) const [fileSearchResults, setFileSearchResults] = useState([]) const [searchLoading, setSearchLoading] = useState(false) @@ -1016,6 +1021,84 @@ const ChatTextArea = forwardRef( } }, [showModelSelector]) + // Effect for Shift key hold detection + useEffect(() => { + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === "Shift" && !event.repeat) { + // Start timer only if Shift is pressed and not already held down + if (shiftHoldTimerRef.current === null) { + shiftHoldTimerRef.current = setTimeout(() => { + setShowShiftDragTip(true) + }, 250) // 250ms delay + } + } + } + + const handleKeyUp = (event: KeyboardEvent) => { + if (event.key === "Shift") { + // Clear timer and hide tip when Shift is released + if (shiftHoldTimerRef.current !== null) { + clearTimeout(shiftHoldTimerRef.current) + shiftHoldTimerRef.current = null + } + setShowShiftDragTip(false) + } + } + + // Add listeners + window.addEventListener("keydown", handleKeyDown) + window.addEventListener("keyup", handleKeyUp) + + // Cleanup listeners on component unmount + return () => { + window.removeEventListener("keydown", handleKeyDown) + window.removeEventListener("keyup", handleKeyUp) + // Clear any running timer on unmount + if (shiftHoldTimerRef.current !== null) { + clearTimeout(shiftHoldTimerRef.current) + } + } + }, []) // Empty dependency array ensures this runs only once on mount/unmount + + // Function to show error message for unsupported files for drag and drop + const showUnsupportedFileErrorMessage = () => { + // Show error message for unsupported files + setShowUnsupportedFileError(true) + + // Clear any existing timer + if (unsupportedFileTimerRef.current) { + clearTimeout(unsupportedFileTimerRef.current) + } + + // Set timer to hide error after 3 seconds + unsupportedFileTimerRef.current = setTimeout(() => { + setShowUnsupportedFileError(false) + unsupportedFileTimerRef.current = null + }, 3000) + } + + const handleDragEnter = (e: React.DragEvent) => { + e.preventDefault() + setIsDraggingOver(true) + + // Check if files are being dragged + if (e.dataTransfer.types.includes("Files")) { + // Check if any of the files are not images + const items = Array.from(e.dataTransfer.items) + const hasNonImageFile = items.some((item) => { + if (item.kind === "file") { + const type = item.type.split("/")[0] + return type !== "image" + } + return false + }) + + if (hasNonImageFile) { + showUnsupportedFileErrorMessage() + } + } + } + /** * Handles the drag over event to allow dropping. * Prevents the default behavior to enable drop. @@ -1024,8 +1107,37 @@ const ChatTextArea = forwardRef( */ const onDragOver = (e: React.DragEvent) => { e.preventDefault() + // Ensure state remains true if dragging continues over the element + if (!isDraggingOver) { + setIsDraggingOver(true) + } } + const handleDragLeave = (e: React.DragEvent) => { + e.preventDefault() + // Check if the related target is still within the drop zone; prevents flickering + const dropZone = e.currentTarget as HTMLElement + if (!dropZone.contains(e.relatedTarget as Node)) { + setIsDraggingOver(false) + // Don't clear the error message here, let it time out naturally + } + } + + // Effect to detect when drag operation ends outside the component + useEffect(() => { + const handleGlobalDragEnd = () => { + // This will be triggered when the drag operation ends anywhere + setIsDraggingOver(false) + // Don't clear error message, let it time out naturally + } + + document.addEventListener("dragend", handleGlobalDragEnd) + + return () => { + document.removeEventListener("dragend", handleGlobalDragEnd) + } + }, []) + /** * Handles the drop event for files and text. * Processes dropped images and text, updating the state accordingly. @@ -1034,6 +1146,14 @@ const ChatTextArea = forwardRef( */ const onDrop = async (e: React.DragEvent) => { e.preventDefault() + setIsDraggingOver(false) // Reset state on drop + + // Clear any error message when something is actually dropped + setShowUnsupportedFileError(false) + if (unsupportedFileTimerRef.current) { + clearTimeout(unsupportedFileTimerRef.current) + unsupportedFileTimerRef.current = null + } // --- 1. VSCode Explorer Drop Handling --- let uris: string[] = [] @@ -1153,9 +1273,37 @@ const ChatTextArea = forwardRef( opacity: textAreaDisabled ? 0.5 : 1, position: "relative", display: "flex", + // Drag-over styles moved to DynamicTextArea + transition: "background-color 0.1s ease-in-out, border 0.1s ease-in-out", }} onDrop={onDrop} - onDragOver={onDragOver}> + onDragOver={onDragOver} + onDragEnter={handleDragEnter} + onDragLeave={handleDragLeave}> + {showUnsupportedFileError && ( +
+ + Only image files are supported + +
+ )} {showSlashCommandsMenu && (
( } onHeightChange?.(height) }} - placeholder={placeholderText} + placeholder={showUnsupportedFileError ? "" : placeholderText} maxRows={10} autoFocus={true} style={{ @@ -1282,9 +1430,13 @@ const ChatTextArea = forwardRef( cursor: textAreaDisabled ? "not-allowed" : undefined, flex: 1, zIndex: 1, - outline: isTextAreaFocused - ? `1px solid ${chatSettings.mode === "plan" ? PLAN_MODE_COLOR : "var(--vscode-focusBorder)"}` - : "none", + outline: + isDraggingOver && !showUnsupportedFileError // Only show drag outline if not showing error + ? "2px dashed var(--vscode-focusBorder)" + : isTextAreaFocused + ? `1px solid ${chatSettings.mode === "plan" ? PLAN_MODE_COLOR : "var(--vscode-focusBorder)"}` + : "none", + outlineOffset: isDraggingOver && !showUnsupportedFileError ? "1px" : "0px", // Add offset for drag-over outline }} onScroll={() => updateHighlights()} /> @@ -1346,83 +1498,129 @@ const ChatTextArea = forwardRef(
- - - - - - @ - - {/* {showButtonText && Context} */} - - - + {/* Always render both components, but control visibility with CSS */} +
+ {/* ButtonGroup - always in DOM but visibility controlled */} + + + + + + @ + + + + - - { - if (!shouldDisableImages) { - onSelectImages() - } - }} - style={{ padding: "0px 0px", height: "20px" }}> - - - {/* {showButtonText && Images} */} - - - - - - - - { - // if (e.key === "Enter" || e.key === " ") { - // e.preventDefault() - // handleModelButtonClick() - // } - // }} - tabIndex={0}> - {modelDisplayName} - - - {showModelSelector && ( - - - - )} - - + + { + if (!shouldDisableImages) { + onSelectImages() + } + }} + style={{ padding: "0px 0px", height: "20px" }}> + + + + + + + + + + + {modelDisplayName} + + + {showModelSelector && ( + + + + )} + + + + {/* Shift Tip - always in DOM but visibility controlled */} +
+ + Hold Shift to Drag Files + +
+
+ {/* Tooltip for Plan/Act toggle remains outside the conditional rendering */}