@@ -13,6 +13,8 @@ import { MAX_IMAGES_PER_MESSAGE } from "./ChatView"
1313import ContextMenu from "./ContextMenu"
1414import Thumbnails from "../common/Thumbnails"
1515
16+ declare const vscode : any ;
17+
1618interface ChatTextAreaProps {
1719 inputValue : string
1820 setInputValue : ( value : string ) => void
@@ -427,7 +429,62 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
427429 opacity : textAreaDisabled ? 0.5 : 1 ,
428430 position : "relative" ,
429431 display : "flex" ,
430- } } >
432+ } }
433+ onDrop = { async ( e ) => {
434+ console . log ( "onDrop called" )
435+ e . preventDefault ( )
436+ const files = Array . from ( e . dataTransfer . files )
437+ const text = e . dataTransfer . getData ( "text" )
438+ if ( text ) {
439+ const newValue =
440+ inputValue . slice ( 0 , cursorPosition ) + text + inputValue . slice ( cursorPosition )
441+ setInputValue ( newValue )
442+ const newCursorPosition = cursorPosition + text . length
443+ setCursorPosition ( newCursorPosition )
444+ setIntendedCursorPosition ( newCursorPosition )
445+ return
446+ }
447+ const acceptedTypes = [ "png" , "jpeg" , "webp" ]
448+ const imageFiles = files . filter ( ( file ) => {
449+ const [ type , subtype ] = file . type . split ( "/" )
450+ return type === "image" && acceptedTypes . includes ( subtype )
451+ } )
452+ if ( ! shouldDisableImages && imageFiles . length > 0 ) {
453+ const imagePromises = imageFiles . map ( ( file ) => {
454+ return new Promise < string | null > ( ( resolve ) => {
455+ const reader = new FileReader ( )
456+ reader . onloadend = ( ) => {
457+ if ( reader . error ) {
458+ console . error ( "Error reading file:" , reader . error )
459+ resolve ( null )
460+ } else {
461+ const result = reader . result
462+ console . log ( "File read successfully" , result )
463+ resolve ( typeof result === "string" ? result : null )
464+ }
465+ }
466+ reader . readAsDataURL ( file )
467+ } )
468+ } )
469+ const imageDataArray = await Promise . all ( imagePromises )
470+ const dataUrls = imageDataArray . filter ( ( dataUrl ) : dataUrl is string => dataUrl !== null )
471+ if ( dataUrls . length > 0 ) {
472+ setSelectedImages ( ( prevImages ) => [ ...prevImages , ...dataUrls ] . slice ( 0 , MAX_IMAGES_PER_MESSAGE ) )
473+ if ( typeof vscode !== 'undefined' ) {
474+ vscode . postMessage ( {
475+ type : 'draggedImages' ,
476+ dataUrls : dataUrls
477+ } )
478+ }
479+ } else {
480+ console . warn ( "No valid images were processed" )
481+ }
482+ }
483+ } }
484+ onDragOver = { ( e ) => {
485+ e . preventDefault ( )
486+ } }
487+ >
431488 { showContextMenu && (
432489 < div ref = { contextMenuContainerRef } >
433490 < ContextMenu
@@ -508,7 +565,8 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
508565 onHeightChange ?.( height )
509566 } }
510567 placeholder = { placeholderText }
511- maxRows = { 10 }
568+ minRows = { 2 }
569+ maxRows = { 20 }
512570 autoFocus = { true }
513571 style = { {
514572 width : "100%" ,
@@ -523,7 +581,6 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
523581 resize : "none" ,
524582 overflowX : "hidden" ,
525583 overflowY : "scroll" ,
526- scrollbarWidth : "none" ,
527584 // Since we have maxRows, when text is long enough it starts to overflow the bottom padding, appearing behind the thumbnails. To fix this, we use a transparent border to push the text up instead. (https://stackoverflow.com/questions/42631947/maintaining-a-padding-inside-of-text-area/52538410#52538410)
528585 // borderTop: "9px solid transparent",
529586 borderLeft : 0 ,
@@ -560,11 +617,11 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
560617 < div
561618 style = { {
562619 position : "absolute" ,
563- right : 23 ,
620+ right : 28 ,
564621 display : "flex" ,
565- alignItems : "flex-center " ,
622+ alignItems : "flex-end " ,
566623 height : textAreaBaseHeight || 31 ,
567- bottom : 9.5 , // should be 10 but doesnt look good on mac
624+ bottom : 18 ,
568625 zIndex : 2 ,
569626 } } >
570627 < div style = { { display : "flex" , flexDirection : "row" , alignItems : "center" } } >
0 commit comments