@@ -29,8 +29,7 @@ import { UntitledTextEditorInput } from '../../../services/untitled/common/untit
29
29
import { IChatRequestVariableEntry , IDiagnosticVariableEntry , IDiagnosticVariableEntryFilterData , ISymbolVariableEntry } from '../common/chatModel.js' ;
30
30
import { ChatAttachmentModel } from './chatAttachmentModel.js' ;
31
31
import { IChatInputStyles } from './chatInputPart.js' ;
32
- import { imageToHash } from './chatPasteProviders.js' ;
33
- import { convertStringToUInt8Array , resizeImage } from './imageUtils.js' ;
32
+ import { resizeImage } from './imageUtils.js' ;
34
33
35
34
enum ChatDragAndDropType {
36
35
FILE_INTERNAL ,
@@ -171,8 +170,8 @@ export class ChatDragAndDrop extends Themable {
171
170
// This is an esstimation based on the datatransfer types/items
172
171
if ( this . isImageDnd ( e ) ) {
173
172
return this . extensionService . extensions . some ( ext => isProposedApiEnabled ( ext , 'chatReferenceBinaryData' ) ) ? ChatDragAndDropType . IMAGE : undefined ;
174
- } else if ( containsDragType ( e , 'text/html' ) ) {
175
- return ChatDragAndDropType . HTML ;
173
+ // } else if (containsDragType(e, 'text/html')) {
174
+ // return ChatDragAndDropType.HTML;
176
175
} else if ( containsDragType ( e , CodeDataTransfers . SYMBOLS ) ) {
177
176
return ChatDragAndDropType . SYMBOL ;
178
177
} else if ( containsDragType ( e , CodeDataTransfers . MARKERS ) ) {
@@ -244,10 +243,11 @@ export class ChatDragAndDrop extends Themable {
244
243
return this . resolveSymbolsAttachContext ( data ) ;
245
244
}
246
245
247
- if ( containsDragType ( e , 'text/html' ) ) {
248
- const data = e . dataTransfer ?. getData ( 'text/html' ) ;
249
- return data ? this . resolveHTMLAttachContext ( data ) : [ ] ;
250
- }
246
+ // Removing HTML support for now
247
+ // if (containsDragType(e, 'text/html')) {
248
+ // const data = e.dataTransfer?.getData('text/html');
249
+ // return data ? this.resolveHTMLAttachContext(data) : [];
250
+ // }
251
251
252
252
const data = extractEditorsDropData ( e ) ;
253
253
return coalesce ( await Promise . all ( data . map ( editorInput => {
@@ -324,55 +324,55 @@ export class ChatDragAndDrop extends Themable {
324
324
} ) ;
325
325
}
326
326
327
- private async resolveHTMLAttachContext ( data : string ) : Promise < IChatRequestVariableEntry [ ] > {
328
- const displayName = localize ( 'dragAndDroppedImageName' , 'Image from URL' ) ;
329
- let finalDisplayName = displayName ;
330
-
331
- for ( let appendValue = 2 ; this . attachmentModel . attachments . some ( attachment => attachment . name === finalDisplayName ) ; appendValue ++ ) {
332
- finalDisplayName = `${ displayName } ${ appendValue } ` ;
333
- }
334
-
335
- const { src, alt } = extractImageAttributes ( data ) ;
336
- finalDisplayName = alt ?? finalDisplayName ;
337
-
338
- if ( / ^ d a t a : i m a g e \/ [ a - z ] + ; b a s e 6 4 , / . test ( src ) ) {
339
- const resizedImage = await resizeImage ( src ) ;
340
- return [ {
341
- id : await imageToHash ( resizedImage ) ,
342
- name : finalDisplayName ,
343
- value : resizedImage ,
344
- isImage : true ,
345
- isFile : false ,
346
- isDirectory : false
347
- } ] ;
348
- } else if ( / ^ h t t p s ? : \/ \/ .+ / . test ( src ) ) {
349
- const url = new URL ( src ) ;
350
- const isImage = / \. ( j p g | j p e g | p n g | g i f | w e b p ) $ / i. test ( url . pathname ) ;
351
- if ( isImage ) {
352
- const buffer = convertStringToUInt8Array ( src ) ;
353
- return [ {
354
- kind : 'image' ,
355
- id : url . toString ( ) ,
356
- name : finalDisplayName ,
357
- value : buffer ,
358
- isImage,
359
- isFile : false ,
360
- isDirectory : false ,
361
- isURL : true ,
362
- } ] ;
363
- } else {
364
- return [ {
365
- kind : 'link' ,
366
- id : url . toString ( ) ,
367
- name : finalDisplayName ,
368
- value : URI . parse ( url . toString ( ) ) ,
369
- isFile : false ,
370
- isDirectory : false ,
371
- } ] ;
372
- }
373
- }
374
- return [ ] ;
375
- }
327
+ // private async resolveHTMLAttachContext(data: string): Promise<IChatRequestVariableEntry[]> {
328
+ // const displayName = localize('dragAndDroppedImageName', 'Image from URL');
329
+ // let finalDisplayName = displayName;
330
+
331
+ // for (let appendValue = 2; this.attachmentModel.attachments.some(attachment => attachment.name === finalDisplayName); appendValue++) {
332
+ // finalDisplayName = `${displayName} ${appendValue}`;
333
+ // }
334
+
335
+ // const { src, alt } = extractImageAttributes(data);
336
+ // finalDisplayName = alt ?? finalDisplayName;
337
+
338
+ // if (/^data:image\/[a-z]+;base64,/.test(src)) {
339
+ // const resizedImage = await resizeImage(src);
340
+ // return [{
341
+ // id: await imageToHash(resizedImage),
342
+ // name: finalDisplayName,
343
+ // value: resizedImage,
344
+ // isImage: true,
345
+ // isFile: false,
346
+ // isDirectory: false
347
+ // }];
348
+ // } else if (/^https?:\/\/.+/.test(src)) {
349
+ // const url = new URL(src);
350
+ // const isImage = /\.(jpg|jpeg|png|gif|webp)$/i.test(url.pathname);
351
+ // if (isImage) {
352
+ // const buffer = convertStringToUInt8Array(src);
353
+ // return [{
354
+ // kind: 'image',
355
+ // id: url.toString(),
356
+ // name: finalDisplayName,
357
+ // value: buffer,
358
+ // isImage,
359
+ // isFile: false,
360
+ // isDirectory: false,
361
+ // isURL: true,
362
+ // }];
363
+ // } else {
364
+ // return [{
365
+ // kind: 'link',
366
+ // id: url.toString(),
367
+ // name: finalDisplayName,
368
+ // value: URI.parse(url.toString()),
369
+ // isFile: false,
370
+ // isDirectory: false,
371
+ // }];
372
+ // }
373
+ // }
374
+ // return [];
375
+ // }
376
376
377
377
private resolveMarkerAttachContext ( markers : MarkerTransferData [ ] ) : IDiagnosticVariableEntry [ ] {
378
378
return markers . map ( ( marker ) : IDiagnosticVariableEntry => {
@@ -571,16 +571,16 @@ function symbolId(resource: URI, range?: IRange): string {
571
571
return resource . fsPath + rangePart ;
572
572
}
573
573
574
- function extractImageAttributes ( html : string ) : { src : string ; alt ?: string } {
575
- const imgTagRegex = / < i m g [ ^ > ] + s r c = [ " ' ] ( [ ^ " ' ] + ) [ " ' ] [ ^ > ] * > / ;
576
- const altRegex = / a l t = [ " ' ] ( [ ^ " ' ] + ) [ " ' ] / ;
574
+ // function extractImageAttributes(html: string): { src: string; alt?: string } {
575
+ // const imgTagRegex = /<img[^>]+src=["']([^"']+)["'][^>]*>/;
576
+ // const altRegex = /alt=["']([^"']+)["']/;
577
577
578
- const match = imgTagRegex . exec ( html ) ;
579
- if ( match ) {
580
- const src = match [ 1 ] ;
581
- const altMatch = match [ 0 ] . match ( altRegex ) ;
582
- return { src, alt : altMatch ? altMatch [ 1 ] : undefined } ;
583
- }
578
+ // const match = imgTagRegex.exec(html);
579
+ // if (match) {
580
+ // const src = match[1];
581
+ // const altMatch = match[0].match(altRegex);
582
+ // return { src, alt: altMatch ? altMatch[1] : undefined };
583
+ // }
584
584
585
- return { src : '' , alt : undefined } ;
586
- }
585
+ // return { src: '', alt: undefined };
586
+ // }
0 commit comments