-
Notifications
You must be signed in to change notification settings - Fork 10.1k
feat: support multi-file drag and drop of images #14832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @jackwotherspoon, 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 significantly improves the user experience for interacting with image files in the terminal by enabling robust multi-file drag-and-drop functionality. It introduces intelligent parsing of multiple space-separated file paths, automatically applying the necessary '@' prefix to valid image files while correctly handling filenames with escaped spaces. This ensures that users can seamlessly input multiple images without manual path modification, streamlining workflows that involve visual content. Highlights
Using Gemini Code AssistThe 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
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 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
|
|
Size Change: +1.49 kB (+0.01%) Total Size: 21.6 MB
ℹ️ View Unchanged
|
There was a problem hiding this 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 new utility functions in clipboardUtils.ts for parsing and validating single and multiple file paths, particularly image paths, from pasted text. These utilities handle @ prefixes and escaped spaces (\ ) common in drag-and-drop operations. The useTextBuffer hook in text-buffer.ts was updated to leverage these new utilities, allowing it to automatically prepend @ to valid file paths when pasting multiple paths or paths with escaped spaces. Review comments highlight a critical bug in the splitEscapedPaths function, noting it fails to correctly parse paths enclosed in single quotes, leading to incorrect splitting. Additionally, the review points out an inconsistency in useTextBuffer's logic where single-segment paths bypass multi-segment processing, and suggests that parseImagePath should also handle single quotes. The reviewer also requested additional test cases for splitEscapedPaths, getImagePathFromText, and looksLikeImagePath to cover paths enclosed in single quotes.
|
/gemini review |
There was a problem hiding this 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 introduces robust support for multi-file drag and drop and copy-paste operations, automatically prefixing valid paths with @. This feature significantly enhances user experience by streamlining the process of inputting file paths, especially those containing spaces. The changes include new utility functions splitEscapedPaths and processPastedPaths for intelligent path parsing and validation, along with comprehensive unit tests covering various edge cases, including Windows paths and escaped spaces. Debug logging has also been added to error handling for improved maintainability. The implementation demonstrates careful consideration for correctness, efficiency, and cross-platform compatibility.
| while (i < text.length) { | ||
| const char = text[i]; | ||
|
|
||
| if (char === '\\' && i + 1 < text.length && text[i + 1] === ' ') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an edge case this will get confused by is
/Users/jacobr/git/gemini-cli/silly.txt2\\ /Users/jacobr/git/gemini-cli/test.txt
which is what MacOs will return if the first file ends in a \ and the second file doesn't.
you want to track the number of \ so you ignore slashes that are escaped. only an odd number of slashes in a row followed by a space really indicate an unescaped spaces.
jacob314
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved after the escaping edge case is addressed.
Summary
Adds support for dragging and dropping multiple files into the terminal at once, automatically adding
@prefix to each valid path.Details
splitEscapedPathsutility to parse space-separated paths while preserving escaped spaces in filenamesprocessPastedPathsto handle single and multiple path validation with@prefix insertionPATH_PREFIX_PATTERNconstant for consistent path prefix detection (supports Unix, Windows drive letters, and UNC paths)unescapePathandescapePathconsistently across all path handlingBehavior
Before: Dragging multiple files → inserted as

/path/img1.png /path/img2.pngAfter: Dragging multiple files → becomes

@/path/img1.png @/path/img2.png@prefix/my\ image.png)/my file.png→@/my\ file.png)check this /path/file.png→check this @/path/file.png)/path/to/file)C:\path\to\file)\\server\share\file)Test plan
@prefix@prefix@prefixC:\...)\\server\share\...)Related Issues
Related to #14706
Part 2 of smaller chunks of breaking up.
How to Validate
Pre-Merge Checklist