Skip to content

feat(cli): add native drag-and-drop and Cmd+V clipboard image pasting#27859

Open
pedrogoiania wants to merge 1 commit into
google-gemini:mainfrom
pedrogoiania:feat/terminal-drag-and-drop
Open

feat(cli): add native drag-and-drop and Cmd+V clipboard image pasting#27859
pedrogoiania wants to merge 1 commit into
google-gemini:mainfrom
pedrogoiania:feat/terminal-drag-and-drop

Conversation

@pedrogoiania

Copy link
Copy Markdown

What does this PR do?

This PR brings visual multimodal parity to Gemini CLI by adding first-class terminal drag-and-drop and native Cmd+V / Ctrl+V clipboard image pasting inside standard terminal emulators.

This addresses the long-standing limitation discussed in closed/stale issues #15532 and #5316, making the workflow incredibly fast and polished.

Detailed Changes:

  1. Background Clipboard Image Synchronizer:
    • Implemented a background observer loop inside InputPrompt.tsx that polls the clipboard for raw image buffers (e.g. screenshots).
    • When a new raw image is detected, it automatically saves it to the secure local project temporary directory (~/.gemini/tmp/gemini-cli/images/clipboard-xxx.png) and writes the workspace-relative path text (@.gemini-clipboard/clipboard-xxx.png ) back to the system clipboard.
    • This makes standard Cmd+V paste the file reference natively!
  2. Workspace-Relative Path Resolution:
    • Updated parsePastedPaths in clipboardUtils.ts to accept an optional targetDir parameter.
    • If a dropped/pasted file path is inside the active workspace, it automatically resolves to a clean relative path (e.g., @src/image.png) instead of a long absolute path.
  3. Pasting / Drop Status Toast:
    • Updated the text-buffer.ts input handler to pass the active workspace directory and emit a clean, non-intrusive status toast (e.g. Added logo.png to prompt context) when files are dropped or pasted.
  4. Unit Tests:
    • Added robust tests inside clipboardUtils.test.ts verifying path resolution both inside and outside of the workspace directory.

Closes #27855

@pedrogoiania pedrogoiania requested review from a team as code owners June 12, 2026 13:09
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 enhances the Gemini CLI by introducing native drag-and-drop and clipboard image pasting capabilities. By implementing a background clipboard watcher and improving path resolution logic, the PR streamlines the workflow for adding local files and images to the prompt, providing a more polished and intuitive terminal experience.

Highlights

  • Clipboard Image Synchronization: Implemented a background observer in InputPrompt.tsx that detects raw images in the clipboard, saves them to a temporary directory, and writes a workspace-relative path back to the clipboard for native Cmd+V/Ctrl+V support.
  • Workspace-Relative Path Resolution: Updated parsePastedPaths to support target directory resolution, ensuring dropped or pasted file paths are converted to clean, workspace-relative references.
  • User Feedback: Added non-intrusive status toasts in the text-buffer input handler to confirm when files are successfully dropped or pasted into the prompt context.
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 the 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 counterproductive. 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.

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.

@github-actions github-actions Bot added the size/m A medium sized PR label Jun 12, 2026
@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

📊 PR Size: size/L

  • Lines changed: 260
  • Additions: +222
  • Deletions: -38
  • Files changed: 6

@google-cla

google-cla Bot commented Jun 12, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@pedrogoiania pedrogoiania force-pushed the feat/terminal-drag-and-drop branch 2 times, most recently from 6c65ad5 to 233ee46 Compare June 12, 2026 13:16

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

Copy link
Copy Markdown
Contributor

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 background clipboard image watcher that automatically converts copied raw images into temporary files and writes their relative paths back to the clipboard. It also updates path pasting to resolve paths relatively within the target directory and adds toast notifications when files are added to the prompt context. Feedback on these changes highlights a critical command injection vulnerability in the Windows clipboard writing function, potential path traversal issues due to simple string prefix checks, and a bug where file paths containing spaces are incorrectly split when generating toast notifications.

Comment thread packages/cli/src/ui/utils/clipboardUtils.ts
Comment thread packages/cli/src/ui/utils/clipboardUtils.ts
Comment thread packages/cli/src/ui/utils/clipboardUtils.ts Outdated
Comment thread packages/cli/src/ui/components/shared/text-buffer.ts Outdated
@pedrogoiania pedrogoiania force-pushed the feat/terminal-drag-and-drop branch from 233ee46 to 5a06e33 Compare June 12, 2026 13:17
@github-actions github-actions Bot added the size/l A large sized PR label Jun 12, 2026
@pedrogoiania pedrogoiania force-pushed the feat/terminal-drag-and-drop branch from 5a06e33 to c0b4dd3 Compare June 12, 2026 13:23
@gemini-cli gemini-cli Bot added priority/p3 Backlog - a good idea but not currently a priority. area/core Issues related to User Interface, OS Support, Core Functionality labels Jun 12, 2026
- Implement background clipboard image synchronizer to extract raw images from system clipboard and reframe their relative text paths back to the clipboard on macOS, Windows, and Linux.
- Update parsePastedPaths to support targetDir and convert absolute file paths to clean relative paths inside the workspace.
- Update text-buffer to pass targetDir and emit a transient status toast confirming dropped/pasted files.
- Add comprehensive unit tests for relative path resolution with targetDir.

Closes google-gemini#27855
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality priority/p3 Backlog - a good idea but not currently a priority. size/l A large sized PR size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(cli): add native terminal drag-and-drop and image drop support (multimodal parity)

1 participant