Feature/paste image windows#4107
Conversation
…to feature/paste-image-windows
|
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. |
There was a problem hiding this comment.
Summary of Changes
Hello @youaodu, 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 the capability for the Gemini-cli to paste images from the system clipboard when running on Windows. It includes the necessary platform-specific logic to detect and save clipboard images, implements a new Alt+V keyboard shortcut to facilitate this action on Windows, and updates the user interface to provide a relevant hint.
Highlights
- Windows Clipboard Integration: Enabled the Gemini-cli to paste images directly from the system clipboard on Windows, addressing platform-specific challenges where the Windows terminal intercepts standard paste events.
- New Keyboard Shortcut for Windows: Introduced an
Alt+Vkeyboard shortcut specifically for Windows users to trigger the image pasting functionality, providing an alternative to the commonly interceptedCtrl+V. - Platform-Specific UI Hint: Updated the input prompt's placeholder text to conditionally display the
Alt+Vshortcut hint only when the application is running on a Windows operating system, improving user guidance. - Cross-Platform Clipboard Utilities: Extended the core
clipboardHasImageandsaveClipboardImageutility functions to support Windows by leveraging PowerShell commands, while maintaining existing functionality for macOS.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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 is currently in preview and 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 to provide feedback.
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
-
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. ↩
There was a problem hiding this comment.
Code Review
This pull request adds a great new feature for Windows users, allowing them to paste images from the clipboard. The implementation looks solid, using PowerShell for Windows-specific clipboard operations. My review focuses on a couple of high-severity issues: removing leftover debugging logs that would clutter the user's terminal, and ensuring the new Alt+V shortcut is correctly scoped to Windows to avoid unintended behavior on other platforms. Addressing these will improve the robustness and user experience of the new feature.
| if (key.meta && key.name === 'v') { | ||
| console.error('=== Detected Alt+V key press ==='); | ||
| handleClipboardImage(); | ||
| return; | ||
| } |
There was a problem hiding this comment.
The new Alt+V key handler is intended for Windows only, as indicated by the comment. However, the current implementation is not platform-specific. This could lead to unintended behavior on other operating systems like macOS, where Alt+V is a standard key combination to type the √ character. This handler would incorrectly intercept that input.
Additionally, the console.error call appears to be a leftover from debugging and should be removed to avoid cluttering the user's terminal.
Please scope this handler to Windows and remove the debugging log.
// Alt+V for clipboard image paste (Windows)
if (process.platform === 'win32' && key.meta && key.name === 'v') {
handleClipboardImage();
return;
}There was a problem hiding this comment.
Code Review
This pull request adds support for pasting images from the clipboard on Windows, introducing a new Alt+V shortcut and the necessary platform-specific logic using PowerShell. Error handling for clipboard operations has been made silent, which can lead to a poor user experience and difficult debugging. The path escaping for the PowerShell command on Windows is incomplete and will fail for paths containing single quotes. Addressing these points will improve the feature's robustness and usability.
| } catch (error) { | ||
| console.error('Error handling clipboard image:', error); | ||
| // Ignore clipboard image errors | ||
| } |
There was a problem hiding this comment.
Silently swallowing errors from clipboard operations can lead to a confusing user experience and make debugging difficult. If saveClipboardImage fails (e.g., due to file permissions or an issue with the PowerShell script), the user will receive no feedback, and it will appear as though the paste feature is broken. Re-introduce error logging here to aid in debugging.
} catch (error) {
console.error('Error handling clipboard image:', error);
}| // Windows: Use PowerShell to save clipboard image | ||
| const tempFilePath = path.join(tempDir, `clipboard-${timestamp}.png`); | ||
|
|
||
| // Use a different approach to avoid quote escaping issues |
There was a problem hiding this comment.
remove this comment as it indicates how the code was changed not what it does.
| `powershell -command "Add-Type -AssemblyName System.Windows.Forms; Add-Type -AssemblyName System.Drawing; if ([System.Windows.Forms.Clipboard]::ContainsImage()) { $image = [System.Windows.Forms.Clipboard]::GetImage(); $image.Save('${escapedPath}', [System.Drawing.Imaging.ImageFormat]::Png); Write-Output 'success' } else { Write-Output 'error' }"`, | ||
| ); | ||
|
|
||
| if (stdout.trim() === 'success') { |
There was a problem hiding this comment.
the logic from line 125 on seems duplicated with the mac case. please merge the two.
| const tempFilePath = path.join(tempDir, `clipboard-${timestamp}.png`); | ||
|
|
||
| // Use a different approach to avoid quote escaping issues | ||
| const escapedPath = tempFilePath.replace(/\\/g, '\\\\').replace(/"/g, '`"'); |
There was a problem hiding this comment.
rather than rolling our own shell escaping, it might make sense to use an existing npm package for this.
https://www.npmjs.com/package/shescape?activeTab=code
this package isn't that popular so I am also open to just rolling our own or trying to find a popular package.
|
This would be a great feature to land. Just saw some users on twitter asking about this. When do you think you will have a chance to resolve these minor comments so we can land it? |
Key changes: 1. Refactored `clipboardUtils.ts` by extracting platform-specific logic into separate functions (`saveMacOSClipboardImage`, `saveWindowsClipboardImage`). 2. Introduced `shell-quote` to handle file paths with special characters. 3. Added helper functions for command execution and file cleanup to reduce duplication and improve error handling.
…to feature/paste-image-windows # Conflicts: # .gitignore # packages/cli/src/ui/components/InputPrompt.tsx
|
Hey sorry for the delay here! We still don't have support for this, so we can try to land this if you're willing to address jacob's comments. Thanks |
- placeholder = ' Type your message or @path/to/file',
+ placeholder = process.platform === 'win32'
+ ? ' Type your message or @path/to/file (Alt+V to paste image)'
+ : ' Type your message or @path/to/file',Are you saying we should roll back this part of the code to the previous version? |
# Conflicts: # packages/cli/src/ui/components/InputPrompt.tsx # packages/cli/src/ui/utils/clipboardUtils.ts
|
@abhipatel12 @jacob314 |
|
Closing this PR as it is no longer applicable. Please re-open if needed. |
TLDR
This submission is to enable Gemini-cli to paste images from the clipboard on Windows.
Due to the characteristics of the Windows system terminal, it will intercept the paste event, so a new shortcut key (Alt+v) is enabled here, and the placeHolder is adapted to display this shortcut only on Windows systems.
Reviewer Test Plan
Testing Matrix
PlaceHolder is only displayed under Windows system
The effect after pasting the picture into Input Prompt