Skip to content

Commit 5a676dc

Browse files
authored
temporarily disable web image drag and drop (microsoft#242113)
1 parent ef3a39f commit 5a676dc

File tree

1 file changed

+68
-68
lines changed

1 file changed

+68
-68
lines changed

src/vs/workbench/contrib/chat/browser/chatDragAndDrop.ts

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ import { UntitledTextEditorInput } from '../../../services/untitled/common/untit
2929
import { IChatRequestVariableEntry, IDiagnosticVariableEntry, IDiagnosticVariableEntryFilterData, ISymbolVariableEntry } from '../common/chatModel.js';
3030
import { ChatAttachmentModel } from './chatAttachmentModel.js';
3131
import { IChatInputStyles } from './chatInputPart.js';
32-
import { imageToHash } from './chatPasteProviders.js';
33-
import { convertStringToUInt8Array, resizeImage } from './imageUtils.js';
32+
import { resizeImage } from './imageUtils.js';
3433

3534
enum ChatDragAndDropType {
3635
FILE_INTERNAL,
@@ -171,8 +170,8 @@ export class ChatDragAndDrop extends Themable {
171170
// This is an esstimation based on the datatransfer types/items
172171
if (this.isImageDnd(e)) {
173172
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;
176175
} else if (containsDragType(e, CodeDataTransfers.SYMBOLS)) {
177176
return ChatDragAndDropType.SYMBOL;
178177
} else if (containsDragType(e, CodeDataTransfers.MARKERS)) {
@@ -244,10 +243,11 @@ export class ChatDragAndDrop extends Themable {
244243
return this.resolveSymbolsAttachContext(data);
245244
}
246245

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+
// }
251251

252252
const data = extractEditorsDropData(e);
253253
return coalesce(await Promise.all(data.map(editorInput => {
@@ -324,55 +324,55 @@ export class ChatDragAndDrop extends Themable {
324324
});
325325
}
326326

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-
}
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+
// }
376376

377377
private resolveMarkerAttachContext(markers: MarkerTransferData[]): IDiagnosticVariableEntry[] {
378378
return markers.map((marker): IDiagnosticVariableEntry => {
@@ -571,16 +571,16 @@ function symbolId(resource: URI, range?: IRange): string {
571571
return resource.fsPath + rangePart;
572572
}
573573

574-
function extractImageAttributes(html: string): { src: string; alt?: string } {
575-
const imgTagRegex = /<img[^>]+src=["']([^"']+)["'][^>]*>/;
576-
const altRegex = /alt=["']([^"']+)["']/;
574+
// function extractImageAttributes(html: string): { src: string; alt?: string } {
575+
// const imgTagRegex = /<img[^>]+src=["']([^"']+)["'][^>]*>/;
576+
// const altRegex = /alt=["']([^"']+)["']/;
577577

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+
// }
584584

585-
return { src: '', alt: undefined };
586-
}
585+
// return { src: '', alt: undefined };
586+
// }

0 commit comments

Comments
 (0)