Skip to content

feat: add image paste functionality to DescriptionImageDropZone compo…#116

Merged
webdevcody merged 3 commits intomainfrom
feat/enchance-pasting-images
Dec 16, 2025
Merged

feat: add image paste functionality to DescriptionImageDropZone compo…#116
webdevcody merged 3 commits intomainfrom
feat/enchance-pasting-images

Conversation

@Shironex
Copy link
Collaborator

@Shironex Shironex commented Dec 16, 2025

  • Implemented handlePaste function to process images from clipboard across all OS.
  • Updated the component to handle pasted images and prevent default paste behavior.
  • Enhanced user instructions to include pasting images in the UI.
  • Enhanced chat sessions to see image preview that we attach to message

Added a utility function to simulate pasting images in tests, ensuring cross-platform compatibility.

Now u can either paste image to textare or use browse label to add it as context for your prompt

images preview:

image image

…nent

- Implemented handlePaste function to process images from clipboard across all OS.
- Updated the component to handle pasted images and prevent default paste behavior.
- Enhanced user instructions to include pasting images in the UI.

Added a utility function to simulate pasting images in tests, ensuring cross-platform compatibility.
@Shironex Shironex marked this pull request as ready for review December 16, 2025 01:50
@Shironex Shironex self-assigned this Dec 16, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Shironex, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant user experience improvement by enabling direct image pasting from the clipboard into the DescriptionImageDropZone component. This new feature streamlines the process of adding images, complementing existing drag-and-drop and file browsing options. Additionally, it includes a dedicated testing utility to ensure the reliability and cross-platform compatibility of the new paste functionality.

Highlights

  • Clipboard Image Handling: Implemented a handlePaste function in DescriptionImageDropZone to detect and process images from the clipboard across all operating systems.
  • Component Integration: The DescriptionImageDropZone component now actively listens for paste events, processes clipboard images, and prevents default paste behavior when an image is detected.
  • User Interface Update: User instructions within the component have been updated to inform users about the new image pasting capability.
  • Testing Utility: A new utility function, simulateImagePaste, has been added to apps/app/tests/utils/files/drag-drop.ts to enable robust testing of the image paste functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Shironex Shironex added Enhancement Improvements to existing functionality or UI. Testers-Requested Request for others to test an enhancement or bug fix/etc. Do Not Merge Use this label if something should not be merged. labels Dec 16, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a great new feature, allowing users to paste images directly into the DescriptionImageDropZone. The implementation is solid, covering clipboard data handling across different OS and preventing default paste behavior when images are detected. The accompanying test utility to simulate image pasting is also well-thought-out.

My review includes a couple of suggestions for improvement:

  • In the handlePaste function, I've recommended a small change to ensure uniquely generated filenames when multiple images are pasted simultaneously.
  • In the test utility simulateImagePaste, I've suggested a more modern and concise way to convert base64 strings to Blobs.

Overall, this is a well-executed feature enhancement.

const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
const renamedFile = new File(
[file],
`pasted-image-${timestamp}.${extension}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When pasting multiple images at once, it's possible for them to be processed within the same millisecond, which could result in identical timestamps and thus identical filenames. This could lead to images overwriting each other or being misidentified. To ensure filename uniqueness for each image within a single paste operation, I recommend appending the loop index i to the filename.

Suggested change
`pasted-image-${timestamp}.${extension}`,
`pasted-image-${timestamp}-${i}.${extension}`,

Comment on lines +51 to +62
({ selector, base64, mime }) => {
const target = document.querySelector(selector);
if (!target) throw new Error(`Element not found: ${selector}`);

// Convert base64 to Blob
const byteCharacters = atob(base64);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
const blob = new Blob([byteArray], { type: mime });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current method for converting a base64 string to a Blob is quite verbose. A more modern and concise approach is to use the fetch API with a data URL. This improves readability and maintainability. The page.evaluate callback will need to be marked as async to support this.

Suggested change
({ selector, base64, mime }) => {
const target = document.querySelector(selector);
if (!target) throw new Error(`Element not found: ${selector}`);
// Convert base64 to Blob
const byteCharacters = atob(base64);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
const blob = new Blob([byteArray], { type: mime });
async ({ selector, base64, mime }) => {
const target = document.querySelector(selector);
if (!target) throw new Error(`Element not found: ${selector}`);
// Convert base64 to Blob using fetch
const dataUrl = `data:${mime};base64,${base64}`;
const blob = await (await fetch(dataUrl)).blob();

- Updated ImageAttachment interface to make 'id' and 'size' optional for better compatibility with server messages.
- Improved image display in AgentView for user messages, including a count of attached images and a clickable preview.
- Refined ImageDropZone to conditionally render file size and ensure proper handling of image removal actions.
@Shironex Shironex force-pushed the feat/enchance-pasting-images branch from f419905 to c8c05ef Compare December 16, 2025 02:19
@webdevcody webdevcody merged commit 25044d4 into main Dec 16, 2025
3 checks passed
@webdevcody webdevcody deleted the feat/enchance-pasting-images branch December 16, 2025 02:52
@Shironex Shironex added Ready-To-Merge A feature or bug has been improved/fixed and a final review is requested before merging. and removed Do Not Merge Use this label if something should not be merged. labels Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Improvements to existing functionality or UI. Ready-To-Merge A feature or bug has been improved/fixed and a final review is requested before merging. Testers-Requested Request for others to test an enhancement or bug fix/etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants