Skip to content

Conversation

RomneyDa
Copy link
Collaborator

@RomneyDa RomneyDa commented Oct 7, 2025

#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.

  • Bug Fixes
    • Handle drop/dragover inside a ProseMirror plugin and hide the overlay on drop.
    • Support VS Code “vscode-resource” image drops: parse HTML, resolve the file path, request the file as a data URL, and insert it as an image node.
    • Add readFileAsDataUrl protocol and VS Code handler to read files and return data URLs (png/jpeg).
    • Simplify DragOverlay and make it non-interactive to avoid blocking drops.
    • Gate behavior behind modelSupportsImages to avoid unsupported models.

@RomneyDa RomneyDa requested a review from a team as a code owner October 7, 2025 01:53
@RomneyDa RomneyDa requested review from Patrick-Erichsen and removed request for a team October 7, 2025 01:53
Copy link

github-actions bot commented Oct 7, 2025

⚠️ PR Title Format

Your PR title doesn't follow the conventional commit format, but this won't block your PR from being merged. We recommend using this format for better project organization.

Expected Format:

<type>[optional scope]: <description>

Examples:

  • feat: add changelog generation support
  • fix: resolve login redirect issue
  • docs: update README with new instructions
  • chore: update dependencies

Valid Types:

feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert

This helps with:

  • 📝 Automatic changelog generation
  • 🚀 Automated semantic versioning
  • 📊 Better project history tracking

This is a non-blocking warning - your PR can still be merged without fixing this.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 7, 2025
Copy link

github-actions bot commented Oct 7, 2025

✅ Review Complete

Code Review Summary

⚠️ Continue configuration error. Please verify that the assistant exists in Continue Hub.


Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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";
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Oct 7, 2025

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(&quot;.&quot;).pop() === &quot;png&quot; ? &quot;image/png&quot; : &quot;image/jpeg&quot;;
+      const dataUrl = `data:${fileType};base64,${Buffer.from(
+        fileContents,
</file context>
Suggested change
filepath.split(".").pop() === "png" ? "image/png" : "image/jpeg";
filepath.split(".").pop()?.toLowerCase() === "png" ? "image/png" : "image/jpeg";
Fix with Cubic

}
});
event.preventDefault();
// Let the event bubble to ProseMirror by not preventing default
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Oct 7, 2025

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
       }}
     &gt;
</file context>
Suggested change
// Let the event bubble to ProseMirror by not preventing default
event.preventDefault();
Fix with Cubic

const node = schema.nodes.image.create({
src: dataUrl,
});
const tr = view.state.tr.insert(0, node);
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Oct 7, 2025

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>
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants