Elffuss BraidHub

kikocis/continue public

Merge pull request #7908 from continuedev/revert-7205-fix-image-drop-from-main-editor

Revert "Fix image drop from main editor"
Changeset54e630386bd764bf28db0ccc01e15821b803db77326d620a4dd6ca40bec765bc
AuthorDallin Romney <dallinromney@gmail.com> · 2025-09-22 16:43 -07:00
CommitterGitHub <noreply@github.com> · 2025-09-22 16:43 -07:00
Parents5e2a247f97eb, 4af4016b5aa3

Browse the files at this changeset

9 files changed

modified .vscode/launch.json +1 −1
@@ -18,7 +18,7 @@
1818 ],
1919 "pauseForSourceMap": false,
2020 "outFiles": ["${workspaceFolder}/extensions/vscode/out/extension.js"],
21- "preLaunchTask": "vscode-extension:build-without-watch",
21+ "preLaunchTask": "vscode-extension:build-with-packages",
2222 "env": {
2323 // "CONTROL_PLANE_ENV": "local",
2424 "CONTINUE_GLOBAL_DIR": "${workspaceFolder}/extensions/.continue-debug"
modified .vscode/tasks.json +0 −19
@@ -174,25 +174,6 @@
174174 }
175175 ]
176176 },
177- {
178- "label": "gui:build",
179- "type": "shell",
180- "command": "npm",
181- "options": {
182- "cwd": "${workspaceFolder}/gui",
183- "env": {
184- "NODE_OPTIONS": "--max-old-space-size=4096"
185- }
186- },
187- "args": ["run", "build"],
188- "problemMatcher": ["$tsc"],
189- "presentation": {
190- "group": "build-tasks",
191- "panel": "shared",
192- "reveal": "silent",
193- "close": true
194- }
195- },
196177 {
197178 "label": "binary:esbuild",
198179 "type": "shell",
modified core/protocol/ide.ts +0 −1
@@ -51,7 +51,6 @@
5151 getPinnedFiles: [undefined, string[]];
5252 showLines: [{ filepath: string; startLine: number; endLine: number }, void];
5353 readRangeInFile: [{ filepath: string; range: Range }, string];
54- readFileAsDataUrl: [{ filepath: string }, string];
5554 getDiff: [{ includeUnstaged: boolean }, string[]];
5655 getTerminalContents: [undefined, string];
5756 getDebugLocals: [{ threadIndex: number }, string];
modified extensions/vscode/src/extension/VsCodeMessenger.ts +0 −12
@@ -295,18 +295,6 @@
295295 });
296296 });
297297
298- this.onWebviewOrCore("readFileAsDataUrl", async (msg) => {
299- const { filepath } = msg.data;
300- const fileUri = vscode.Uri.file(filepath);
301- const fileContents = await vscode.workspace.fs.readFile(fileUri);
302- const fileType =
303- filepath.split(".").pop() === "png" ? "image/png" : "image/jpeg";
304- const dataUrl = `data:${fileType};base64,${Buffer.from(
305- fileContents,
306- ).toString("base64")}`;
307- return dataUrl;
308- });
309-
310298 this.onWebviewOrCore("getIdeSettings", async (msg) => {
311299 return ide.getIdeSettings();
312300 });
modified gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx +31 −13
@@ -57,13 +57,10 @@
5757 const historyLength = useAppSelector((store) => store.session.history.length);
5858 const isInEdit = useAppSelector((store) => store.session.isInEdit);
5959
60- const [showDragOverMsg, setShowDragOverMsg] = useState(false);
61-
6260 const { editor, onEnterRef } = createEditorConfig({
6361 props,
6462 ideMessenger,
6563 dispatch,
66- setShowDragOverMsg,
6764 });
6865
6966 // Register the main editor with the provider
@@ -140,6 +137,8 @@
140137 }
141138 }, [isStreaming, props.isMainInput]);
142139
140+ const [showDragOverMsg, setShowDragOverMsg] = useState(false);
141+
143142 const [activeKey, setActiveKey] = useState<string | null>(null);
144143
145144 const insertCharacterWithWhitespace = useCallback(
@@ -222,23 +221,40 @@
222221 if (e.shiftKey) {
223222 setShowDragOverMsg(false);
224223 } else {
225- setTimeout(() => {
226- setShowDragOverMsg(false);
227- }, 2000);
224+ setTimeout(() => setShowDragOverMsg(false), 2000);
228225 }
229226 }
230- setShowDragOverMsg(false);
231227 }}
232228 onDragEnter={() => {
233229 setShowDragOverMsg(true);
234230 }}
235- onDragEnd={() => {
236- setShowDragOverMsg(false);
237- }}
238231 onDrop={(event) => {
239- // Just hide the drag overlay - ProseMirror handles the actual drop
240232 setShowDragOverMsg(false);
241- // Let the event bubble to ProseMirror by not preventing default
233+ if (
234+ !defaultModel ||
235+ !modelSupportsImages(
236+ defaultModel.provider,
237+ defaultModel.model,
238+ defaultModel.title,
239+ defaultModel.capabilities,
240+ )
241+ ) {
242+ return;
243+ }
244+ let file = event.dataTransfer.files[0];
245+ void handleImageFile(ideMessenger, file).then((result) => {
246+ if (!editor) {
247+ return;
248+ }
249+ if (result) {
250+ const [_, dataUrl] = result;
251+ const { schema } = editor.state;
252+ const node = schema.nodes.image.create({ src: dataUrl });
253+ const tr = editor.state.tr.insert(0, node);
254+ editor.view.dispatch(tr);
255+ }
256+ });
257+ event.preventDefault();
242258 }}
243259 >
244260 <div className="px-2.5 pb-1 pt-2">
@@ -283,7 +299,9 @@
283299 defaultModel?.model || "",
284300 defaultModel?.title,
285301 defaultModel?.capabilities,
286- ) && <DragOverlay show={showDragOverMsg} />}
302+ ) && (
303+ <DragOverlay show={showDragOverMsg} setShow={setShowDragOverMsg} />
304+ )}
287305 <div id={TIPPY_DIV_ID} className="fixed z-50" />
288306 </InputBoxDiv>
289307 );
modified gui/src/components/mainInput/TipTapEditor/components/DragOverlay.tsx +25 −2
@@ -1,11 +1,34 @@
1-import React from "react";
1+import React, { useEffect } from "react";
22 import { HoverDiv, HoverTextDiv } from "./StyledComponents";
33
44 interface DragOverlayProps {
55 show: boolean;
6+ setShow: (show: boolean) => void;
67 }
78
8-export const DragOverlay: React.FC<DragOverlayProps> = ({ show }) => {
9+export const DragOverlay: React.FC<DragOverlayProps> = ({ show, setShow }) => {
10+ useEffect(() => {
11+ const overListener = (event: DragEvent) => {
12+ if (event.shiftKey) return;
13+ setShow(true);
14+ };
15+ window.addEventListener("dragover", overListener);
16+
17+ const leaveListener = (event: DragEvent) => {
18+ if (event.shiftKey) {
19+ setShow(false);
20+ } else {
21+ setTimeout(() => setShow(false), 2000);
22+ }
23+ };
24+ window.addEventListener("dragleave", leaveListener);
25+
26+ return () => {
27+ window.removeEventListener("dragover", overListener);
28+ window.removeEventListener("dragleave", leaveListener);
29+ };
30+ }, []);
31+
932 if (!show) return null;
1033
1134 return (
modified gui/src/components/mainInput/TipTapEditor/components/StyledComponents.ts +0 −2
@@ -56,7 +56,6 @@
5656 display: flex;
5757 align-items: center;
5858 justify-content: center;
59- pointer-events: none;
6059 `;
6160
6261 export const HoverTextDiv = styled.div`
@@ -69,5 +68,4 @@
6968 display: flex;
7069 align-items: center;
7170 justify-content: center;
72- pointer-events: none;
7371 `;
modified gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +2 −77
@@ -27,7 +27,7 @@
2727 getContextProviderDropdownOptions,
2828 getSlashCommandDropdownOptions,
2929 } from "./getSuggestion";
30-import { handleImageFile, handleVSCodeResourceFromHtml } from "./imageUtils";
30+import { handleImageFile } from "./imageUtils";
3131
3232 export function getPlaceholderText(
3333 placeholder: TipTapEditorProps["placeholder"],
@@ -69,9 +69,8 @@
6969 props: TipTapEditorProps;
7070 ideMessenger: IIdeMessenger;
7171 dispatch: AppDispatch;
72- setShowDragOverMsg: (show: boolean) => void;
7372 }) {
74- const { props, ideMessenger, dispatch, setShowDragOverMsg } = options;
73+ const { props, ideMessenger, dispatch } = options;
7574
7675 const posthog = usePostHog();
7776
@@ -148,80 +147,6 @@
148147 const plugin = new Plugin({
149148 props: {
150149 handleDOMEvents: {
151- drop(view, event) {
152- // Hide drag overlay immediately when drop is handled
153- setShowDragOverMsg(false);
154-
155- // Get current model and check if it supports images
156- const model = defaultModelRef.current;
157- if (
158- !model ||
159- !modelSupportsImages(
160- model.provider,
161- model.model,
162- model.title,
163- model.capabilities,
164- )
165- ) {
166- event.preventDefault();
167- event.stopPropagation();
168- return true;
169- }
170-
171- event.preventDefault();
172- event.stopPropagation();
173-
174- // Check if dataTransfer exists
175- if (!event.dataTransfer) {
176- return true;
177- }
178-
179- // Handle file drop first
180- if (event.dataTransfer.files.length > 0) {
181- const file = event.dataTransfer.files[0];
182- void handleImageFile(ideMessenger, file).then((result) => {
183- if (result) {
184- const [_, dataUrl] = result;
185- const { schema } = view.state;
186- const node = schema.nodes.image.create({
187- src: dataUrl,
188- });
189- const tr = view.state.tr.insert(0, node);
190- view.dispatch(tr);
191- }
192- });
193- return true;
194- }
195-
196- // Handle drop of HTML content (including VS Code resource URLs)
197- const html = event.dataTransfer.getData("text/html");
198- if (html) {
199- void handleVSCodeResourceFromHtml(ideMessenger, html)
200- .then((dataUrl) => {
201- if (dataUrl) {
202- const { schema } = view.state;
203- const node = schema.nodes.image.create({
204- src: dataUrl,
205- });
206- const tr = view.state.tr.insert(0, node);
207- view.dispatch(tr);
208- }
209- })
210- .catch((err) =>
211- console.error(
212- "Failed to handle VS Code resource:",
213- err,
214- ),
215- );
216- }
217-
218- return true;
219- },
220- dragover(view, event) {
221- // Allow dragover for proper drop handling
222- event.preventDefault();
223- return true;
224- },
225150 paste(view, event) {
226151 const model = defaultModelRef.current;
227152 if (!model) return;
modified gui/src/components/mainInput/TipTapEditor/utils/imageUtils.ts +0 −153
@@ -2,159 +2,6 @@
22
33 const IMAGE_RESOLUTION = 1024;
44
5-/**
6- * Extracts the file path from a VS Code resource URL
7- * Example: "https://file+.vscode-resource.vscode-cdn.net/Users/path/to/file.jpg?version=123"
8- * Returns: "/Users/path/to/file.jpg"
9- */
10-export function extractFilePathFromVSCodeResourceUrl(
11- url: string,
12-): string | null {
13- try {
14- const urlObj = new URL(url);
15- if (urlObj.hostname === "file+.vscode-resource.vscode-cdn.net") {
16- return decodeURIComponent(urlObj.pathname);
17- }
18- return null;
19- } catch (error) {
20- console.error("Error parsing VS Code resource URL:", error);
21- return null;
22- }
23-}
24-
25-/**
26- * Handles VS Code resource URLs by converting them to data URLs
27- * @param ideMessenger - The IDE messenger to communicate with VS Code
28- * @param vscodeResourceUrl - The VS Code resource URL
29- * @returns Promise with the data URL if successful, undefined otherwise
30- */
31-export async function handleVSCodeResourceUrl(
32- ideMessenger: IIdeMessenger,
33- vscodeResourceUrl: string,
34-): Promise<string | undefined> {
35- const filepath = extractFilePathFromVSCodeResourceUrl(vscodeResourceUrl);
36- if (!filepath) {
37- console.error(
38- "Could not extract file path from VS Code resource URL:",
39- vscodeResourceUrl,
40- );
41- return undefined;
42- }
43-
44- console.log("Extracted filepath:", filepath);
45-
46- try {
47- console.log("Requesting readFileAsDataUrl for filepath:", filepath);
48- console.log("About to call ideMessenger.request...");
49-
50- // Add a timeout wrapper to prevent hanging
51- const timeoutPromise = new Promise((_, reject) =>
52- setTimeout(
53- () => reject(new Error("Request timeout after 10 seconds")),
54- 10000,
55- ),
56- );
57-
58- const requestPromise = ideMessenger.request("readFileAsDataUrl", {
59- filepath,
60- });
61-
62- console.log("Request promise created, waiting for response...");
63-
64- const response = await Promise.race([requestPromise, timeoutPromise]);
65-
66- console.log("Got response from ideMessenger.request:", response);
67- console.log("Response type:", typeof response);
68-
69- // The response should be a WebviewSingleMessage which has status and content
70- if (response && typeof response === "object" && "status" in response) {
71- const typedResponse = response as {
72- status: string;
73- error?: string;
74- content?: string;
75- };
76- if (typedResponse.status === "error") {
77- console.error("Error reading file as data URL:", typedResponse.error);
78- return undefined;
79- }
80-
81- if (typedResponse.status === "success" && typedResponse.content) {
82- const dataUrl = typedResponse.content;
83- console.log(
84- "Successfully got data URL for file, content length:",
85- dataUrl.length,
86- );
87- return dataUrl;
88- }
89- }
90-
91- // If response is directly a string (shouldn't happen based on protocol but just in case)
92- if (typeof response === "string") {
93- console.log("Got direct string response, length:", response.length);
94- return response;
95- }
96-
97- console.error("Unexpected response format:", response);
98- return undefined;
99- } catch (error) {
100- console.error("Exception caught when reading file as data URL:", error);
101- console.error(
102- "Error stack:",
103- error instanceof Error ? error.stack : "No stack trace",
104- );
105- return undefined;
106- }
107-}
108-
109-/**
110- * Extracts VS Code resource URL from HTML content
111- * @param html - HTML string that may contain VS Code resource URLs
112- * @returns The VS Code resource URL if found, null otherwise
113- */
114-export function extractVSCodeResourceUrlFromHtml(html: string): string | null {
115- try {
116- // Create a temporary DOM element to parse the HTML
117- const tempDiv = document.createElement("div");
118- tempDiv.innerHTML = html;
119-
120- // Look for img tags with VS Code resource URLs
121- const imgTags = tempDiv.querySelectorAll("img");
122- for (const img of imgTags) {
123- const src = img.getAttribute("src");
124- if (src && src.includes("file+.vscode-resource.vscode-cdn.net")) {
125- return src;
126- }
127- }
128-
129- return null;
130- } catch (error) {
131- console.error("Error parsing HTML for VS Code resource URL:", error);
132- return null;
133- }
134-}
135-
136-/**
137- * Handles HTML content that contains VS Code resource URLs and converts them to usable data URLs
138- * @param ideMessenger - The IDE messenger to communicate with VS Code
139- * @param html - HTML string containing VS Code resource URLs
140- * @returns Promise with the data URL if successful, undefined otherwise
141- */
142-export async function handleVSCodeResourceFromHtml(
143- ideMessenger: IIdeMessenger,
144- html: string,
145-): Promise<string | undefined> {
146- console.log("Processing HTML for VS Code resource URL:", html);
147-
148- const vscodeResourceUrl = extractVSCodeResourceUrlFromHtml(html);
149- if (!vscodeResourceUrl) {
150- console.log("No VS Code resource URL found in HTML");
151- return undefined;
152- }
153-
154- console.log("Found VS Code resource URL:", vscodeResourceUrl);
155- return await handleVSCodeResourceUrl(ideMessenger, vscodeResourceUrl);
156-}
157-
1585 export function getDataUrlForFile(
1596 file: File,
1607 img: HTMLImageElement,