Skip to content

Conversation

@kishan705
Copy link

feat: add cross-platform clipboard image pasting support (#14647)

  • Added @crosscopy/clipboard package for Windows/Linux clipboard support
  • Refactored clipboardUtils to support Windows, macOS, and Linux
  • Maintained macOS fallback using osascript for reliability
  • Added comprehensive test coverage (12 new tests)
  • Users can now paste screenshots with Ctrl+V on all platforms

Fixes #14647

Summary

Implements cross-platform clipboard image pasting support for Windows, macOS, and Linux. Users can now paste screenshots directly from the clipboard using Ctrl+V (or right-click) on all platforms, significantly improving workflow efficiency when working with visual content.

Details

  • New Dependency: Added @crosscopy/[email protected] - a Rust-based native module providing clipboard access across all platforms
  • Cross-Platform Support:
    • Windows: Uses native Windows clipboard APIs via @crosscopy/clipboard
    • Linux: Supports both X11 and Wayland display systems
    • macOS: Uses @crosscopy/clipboard with osascript fallback for maximum reliability
  • Implementation:
    • Images retrieved as base64 and saved as PNG files in .gemini-clipboard/ directory
    • Automatic cleanup of files older than 1 hour
    • Graceful error handling with platform-specific fallbacks
    • Maintains backward compatibility with existing macOS implementation

Related Issues

Fixes #14647

How to Validate

Automated Testing:

npm run build
npm run test -- clipboardUtils.test.ts
npm run typecheck

…ni#14647)

- Added @crosscopy/clipboard package for Windows/Linux clipboard support
- Refactored clipboardUtils to support Windows, macOS, and Linux
- Maintained macOS fallback using osascript for reliability
- Added comprehensive test coverage (12 new tests)
- Users can now paste screenshots with Ctrl+V on all platforms

Fixes google-gemini#14647
@kishan705 kishan705 requested review from a team as code owners December 6, 2025 16:31
@google-cla
Copy link

google-cla bot commented Dec 6, 2025

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kishan705, 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 significant enhancements by enabling cross-platform image pasting directly from the clipboard. It integrates a new native module for robust clipboard access across Windows, macOS, and Linux, ensuring a consistent and efficient workflow for users working with visual content. The changes include refactoring existing utilities, implementing intelligent fallbacks, and adding automated cleanup for temporary image files.

Highlights

  • Cross-Platform Clipboard Support: Implemented image pasting via Ctrl+V on Windows, macOS, and Linux, significantly improving workflow efficiency.
  • New Dependency Integration: Integrated the @crosscopy/clipboard package, a Rust-based native module, for robust cross-platform clipboard access.
  • Refactored Clipboard Utilities: Updated clipboardUtils to leverage the new cross-platform package, including a robust macOS fallback using osascript for maximum reliability.
  • Automated Image Handling: Images are now retrieved as base64, saved as PNGs in a temporary .gemini-clipboard/ directory, and automatically cleaned up after 1 hour.
  • Enhanced Test Coverage: Added 12 new comprehensive tests for clipboard functionality, covering various platforms, error scenarios, and the macOS fallback mechanism.
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.

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

The pull request successfully introduces cross-platform clipboard image pasting support by integrating the @crosscopy/clipboard package and implementing robust fallback mechanisms for macOS. The refactoring of clipboardUtils to handle different platforms and the addition of comprehensive test coverage are commendable. The implementation includes thoughtful error handling and automatic cleanup of temporary files, which enhances the overall reliability and maintainability of the feature.


// Generate a unique filename with timestamp
const timestamp = new Date().getTime();
const tempFilePath = path.join(tempDir, `clipboard-${timestamp}.png`);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The tempFilePath is hardcoded to use the .png extension. However, the saveMacOSClipboardImage fallback function (lines 124-186) explicitly handles various image formats (PNG, JPEG, TIFF, GIF) based on osascript output, indicating that the system clipboard can contain different image types. If the clipboardGetImageBase64() function from @crosscopy/clipboard can return base64 data for image types other than PNG, saving them all with a .png extension could lead to corrupted files or files with incorrect extensions. This is a correctness issue that could make saved images unusable for downstream applications. Please confirm that clipboardGetImageBase64() is guaranteed to only return PNG data, or implement logic to dynamically determine the image format from the base64 data and use the appropriate file extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support clipboard image paste for screenshots on Windows 11

1 participant