diff --git a/webview-ui/src/components/ChatTextArea.tsx b/webview-ui/src/components/ChatTextArea.tsx index 4099da0..59bd63f 100644 --- a/webview-ui/src/components/ChatTextArea.tsx +++ b/webview-ui/src/components/ChatTextArea.tsx @@ -275,6 +275,22 @@ const ChatTextArea = forwardRef( const handlePaste = useCallback( async (e: React.ClipboardEvent) => { const items = e.clipboardData.items + + const pastedText = e.clipboardData.getData("text") + // Check if the pasted content is a URL, add space after so user can easily delete if they don't want it + const urlRegex = /^\S+:\/\/\S+$/ + if (urlRegex.test(pastedText.trim())) { + e.preventDefault() + const trimmedUrl = pastedText.trim() + const newValue = + inputValue.slice(0, cursorPosition) + trimmedUrl + " " + inputValue.slice(cursorPosition) + setInputValue(newValue) + const newCursorPosition = cursorPosition + trimmedUrl.length + 1 + setCursorPosition(newCursorPosition) + setIntendedCursorPosition(newCursorPosition) + return + } + const acceptedTypes = ["png", "jpeg", "webp"] // supported by anthropic and openrouter (jpg is just a file extension but the image will be recognized as jpeg) const imageItems = Array.from(items).filter((item) => { const [type, subtype] = item.type.split("/") @@ -312,7 +328,7 @@ const ChatTextArea = forwardRef( } } }, - [shouldDisableImages, setSelectedImages] + [shouldDisableImages, setSelectedImages, cursorPosition, setInputValue, inputValue] ) const handleThumbnailsHeightChange = useCallback((height: number) => {