-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fix image drop from main editor #8115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…-image-drop-from-main-editor
…-image-drop-from-main-editor
…adarshkt/fix-image-drop-from-main-editor
|
✅ Review Complete Code Review Summary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 issues found across 7 files
Prompt for AI agents (all 3 issues)
Understand the root cause of the following 3 issues and fix them.
<file name="extensions/vscode/src/extension/VsCodeMessenger.ts">
<violation number="1" location="extensions/vscode/src/extension/VsCodeMessenger.ts:306">
Uppercase image extensions (e.g. foo.PNG) hit this branch and get labeled image/jpeg even though the bytes are PNG, producing a mismatched data URL that can fail to render; normalize the extension before comparing.</violation>
</file>
<file name="gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx">
<violation number="1" location="gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx:241">
Dropping a file on InputBoxDiv areas outside the ProseMirror view (like the toolbar) now navigates the browser to that file because this handler no longer calls event.preventDefault(), and the new drop plugin in utils/editorConfig.ts only runs for drops that originate on the editor DOM. Please continue to cancel the default action here to keep the page from navigating away.</violation>
</file>
<file name="gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts">
<violation number="1" location="gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts:189">
The drop handler always inserts the image at document position 0, so every dropped image appears at the top instead of the drop point. Please compute the drop insertion position (e.g., using the drop selection or view.posAtCoords) before inserting.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai
to give feedback, ask questions, or re-run the review.
const fileUri = vscode.Uri.file(filepath); | ||
const fileContents = await vscode.workspace.fs.readFile(fileUri); | ||
const fileType = | ||
filepath.split(".").pop() === "png" ? "image/png" : "image/jpeg"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uppercase image extensions (e.g. foo.PNG) hit this branch and get labeled image/jpeg even though the bytes are PNG, producing a mismatched data URL that can fail to render; normalize the extension before comparing.
Prompt for AI agents
Address the following comment on extensions/vscode/src/extension/VsCodeMessenger.ts at line 306:
<comment>Uppercase image extensions (e.g. foo.PNG) hit this branch and get labeled image/jpeg even though the bytes are PNG, producing a mismatched data URL that can fail to render; normalize the extension before comparing.</comment>
<file context>
@@ -298,6 +298,18 @@ export class VsCodeMessenger {
+ const fileUri = vscode.Uri.file(filepath);
+ const fileContents = await vscode.workspace.fs.readFile(fileUri);
+ const fileType =
+ filepath.split(".").pop() === "png" ? "image/png" : "image/jpeg";
+ const dataUrl = `data:${fileType};base64,${Buffer.from(
+ fileContents,
</file context>
filepath.split(".").pop() === "png" ? "image/png" : "image/jpeg"; | |
filepath.split(".").pop()?.toLowerCase() === "png" ? "image/png" : "image/jpeg"; |
} | ||
}); | ||
event.preventDefault(); | ||
// Let the event bubble to ProseMirror by not preventing default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropping a file on InputBoxDiv areas outside the ProseMirror view (like the toolbar) now navigates the browser to that file because this handler no longer calls event.preventDefault(), and the new drop plugin in utils/editorConfig.ts only runs for drops that originate on the editor DOM. Please continue to cancel the default action here to keep the page from navigating away.
Prompt for AI agents
Address the following comment on gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx at line 241:
<comment>Dropping a file on InputBoxDiv areas outside the ProseMirror view (like the toolbar) now navigates the browser to that file because this handler no longer calls event.preventDefault(), and the new drop plugin in utils/editorConfig.ts only runs for drops that originate on the editor DOM. Please continue to cancel the default action here to keep the page from navigating away.</comment>
<file context>
@@ -221,40 +222,23 @@ function TipTapEditorInner(props: TipTapEditorProps) {
- }
- });
- event.preventDefault();
+ // Let the event bubble to ProseMirror by not preventing default
}}
>
</file context>
// Let the event bubble to ProseMirror by not preventing default | |
event.preventDefault(); |
const node = schema.nodes.image.create({ | ||
src: dataUrl, | ||
}); | ||
const tr = view.state.tr.insert(0, node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The drop handler always inserts the image at document position 0, so every dropped image appears at the top instead of the drop point. Please compute the drop insertion position (e.g., using the drop selection or view.posAtCoords) before inserting.
Prompt for AI agents
Address the following comment on gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts at line 189:
<comment>The drop handler always inserts the image at document position 0, so every dropped image appears at the top instead of the drop point. Please compute the drop insertion position (e.g., using the drop selection or view.posAtCoords) before inserting.</comment>
<file context>
@@ -147,6 +148,80 @@ export function createEditorConfig(options: {
+ const node = schema.nodes.image.create({
+ src: dataUrl,
+ });
+ const tr = view.state.tr.insert(0, node);
+ view.dispatch(tr);
+ }
</file context>
#7910
Summary by cubic
Fixes image drag-and-drop in the main TipTap editor so users can drop local files and images from VS Code and have them insert correctly.