-
Notifications
You must be signed in to change notification settings - Fork 13k
Treat pasted image paths as literal text in shell mode #24715
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,28 @@ pub struct PastedImageInfo { | |
| pub encoded_format: EncodedImageFormat, // Always PNG for now. | ||
| } | ||
|
|
||
| #[cfg(not(target_os = "android"))] | ||
| pub fn paste_text_or_file_path() -> Result<Option<String>, String> { | ||
| let mut cb = arboard::Clipboard::new().map_err(|e| format!("clipboard unavailable: {e}"))?; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In WSL shell mode, this new text/file-path clipboard path returns immediately when Useful? React with 👍 / 👎. |
||
|
|
||
| if let Ok(text) = cb.get_text() | ||
| && !text.is_empty() | ||
| { | ||
| return Ok(Some(text)); | ||
| } | ||
|
|
||
| let files = cb.get().file_list().unwrap_or_default(); | ||
| Ok(files | ||
| .into_iter() | ||
| .next() | ||
| .map(|path| path.to_string_lossy().into_owned())) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the shell-mode paste shortcut falls back to an OS file-list entry, this returns the raw filesystem path and Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| #[cfg(target_os = "android")] | ||
| pub fn paste_text_or_file_path() -> Result<Option<String>, String> { | ||
| Ok(None) | ||
| } | ||
|
|
||
| /// Capture image from system clipboard, encode to PNG, and return bytes + info. | ||
| #[cfg(not(target_os = "android"))] | ||
| pub fn paste_image_as_png() -> Result<(Vec<u8>, PastedImageInfo), PasteImageError> { | ||
|
|
||
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.
This only disables image-path attachment when the internal bash-mode flag is set, but the rest of the composer treats leading-whitespace bang input as a shell command:
is_bang_shell_command()usestrim_start(), and submission trims before shell dispatch. In a draft like!python script.py, pasting/tmp/a.pngstill attaches an image placeholder instead of inserting the literal path, so the submitted shell command receives[Image #1]rather than the file path. The new image-paste shortcut has the samestarts_with('!')limitation, so both paste paths should use the same trimmed shell-command predicate.Useful? React with 👍 / 👎.