Fix clipboard image paste in WSL terminals (#65362)

## Why

VS Code on Windows can interpret `Ctrl+Alt+V` as AltGr input before
Codex receives it. The Windows clipboard fallback also needs to work
when WSL does not import the Windows `PATH`.

## What changed

- Show `Alt+V` in the shortcut guide for WSL sessions in VS Code or when
  terminal detection is inconclusive. Let active bindings and chord
  prefixes take precedence over `Alt+V` and hide the hint when it
  conflicts in the composer.
- Read Windows clipboard images through WinForms, which supports both
  Windows PowerShell 5.1 and PowerShell 7. Try their standard Windows
  installation paths when lookup on `PATH` fails, within the same paste
  deadline.

## Testing

Cover shortcut selection, hint visibility, and `Alt+V` dispatch,
including submitting or queueing a draft when `composer.queue` is
bound to `Alt+V`.

GitOrigin-RevId: ad59ce6c5de65600aa01028f0d173c42a752beae
This commit is contained in:
Felipe Coury
2026-12-03 00:13:35 +00:00
committed by copyberry
parent 39b9b74ef2
commit e6a7862259
12 changed files with 216 additions and 72 deletions
@@ -839,6 +839,7 @@ impl ChatComposer {
.primary_hint(KeymapContext::Composer, "toggle_shortcuts"),
shortcut_guide_keys: super::shortcut_overlay::ShortcutGuideKeys::from_keymap(
&default_keymap,
crate::terminal_capabilities::image_paste_shortcut(),
),
history_search_key: default_keymap
.primary_hint(KeymapContext::Composer, "history_search_previous"),
@@ -1154,8 +1155,10 @@ impl ChatComposer {
self.footer.queue_key = keymap.primary_hint(KeymapContext::Composer, "queue");
self.footer.toggle_shortcuts_key =
keymap.primary_hint(KeymapContext::Composer, "toggle_shortcuts");
self.footer.shortcut_guide_keys =
super::shortcut_overlay::ShortcutGuideKeys::from_keymap(keymap);
self.footer.shortcut_guide_keys = super::shortcut_overlay::ShortcutGuideKeys::from_keymap(
keymap,
crate::terminal_capabilities::image_paste_shortcut(),
);
self.footer.history_search_key =
keymap.primary_hint(KeymapContext::Composer, "history_search_previous");
self.footer.reasoning_down_key =
@@ -102,27 +102,13 @@ pub(crate) struct ComposerRenderOptions<'a> {
impl super::ChatComposer {
pub(super) fn footer_props(&self) -> FooterProps {
let mode = self.footer_mode();
let is_wsl = {
#[cfg(target_os = "linux")]
{
matches!(mode, FooterMode::ShortcutOverlay(_))
&& crate::clipboard_paste::is_probably_wsl()
}
#[cfg(not(target_os = "linux"))]
{
false
}
};
FooterProps {
mode,
mode: self.footer_mode(),
esc_backtrack_hint: self.footer.esc_backtrack_hint,
is_task_running: self.is_task_running,
queue_submissions: self.queue_submissions,
quit_shortcut_key: self.footer.quit_shortcut_key,
collaboration_modes_enabled: self.collaboration_modes_enabled,
is_wsl,
status_line_value: self.footer.status_line_value.clone(),
status_line_enabled: self.footer.status_line_enabled,
key_hints: FooterKeyHints {
+1 -23
View File
@@ -57,7 +57,6 @@ pub(crate) struct FooterProps {
pub(crate) is_task_running: bool,
pub(crate) queue_submissions: bool,
pub(crate) collaboration_modes_enabled: bool,
pub(crate) is_wsl: bool,
/// Which key the user must press again to quit.
///
/// This is rendered when `mode` is `FooterMode::QuitShortcutReminder`.
@@ -116,6 +115,7 @@ impl FooterKeyHints {
toggle_shortcuts: Some(key_hint::plain(KeyCode::Char('?')).into()),
shortcut_guide: shortcut_overlay::ShortcutGuideKeys::from_keymap(
&crate::keymap::RuntimeKeymap::defaults(),
key_hint::ctrl(KeyCode::Char('v')),
),
queue: Some(key_hint::plain(KeyCode::Tab).into()),
insert_newline: Some(key_hint::ctrl(KeyCode::Char('j')).into()),
@@ -1283,7 +1283,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: false,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: false,
@@ -1300,7 +1299,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: false,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: false,
@@ -1320,7 +1318,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: true,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: false,
@@ -1337,7 +1334,6 @@ mod tests {
is_task_running: true,
queue_submissions: false,
collaboration_modes_enabled: false,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: false,
@@ -1354,7 +1350,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: false,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: false,
@@ -1371,7 +1366,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: false,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: false,
@@ -1388,7 +1382,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: false,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: false,
@@ -1405,7 +1398,6 @@ mod tests {
is_task_running: true,
queue_submissions: false,
collaboration_modes_enabled: false,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: false,
@@ -1424,7 +1416,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: false,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: false,
@@ -1443,7 +1434,6 @@ mod tests {
is_task_running: true,
queue_submissions: false,
collaboration_modes_enabled: false,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: false,
@@ -1458,7 +1448,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: true,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: false,
@@ -1486,7 +1475,6 @@ mod tests {
is_task_running: true,
queue_submissions: false,
collaboration_modes_enabled: true,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: false,
@@ -1507,7 +1495,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: false,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: Some(Line::from("Status line content".to_string()).into()),
status_line_enabled: true,
@@ -1523,7 +1510,6 @@ mod tests {
is_task_running: true,
queue_submissions: false,
collaboration_modes_enabled: false,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: Some(Line::from("Status line content".to_string()).into()),
status_line_enabled: true,
@@ -1539,7 +1525,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: false,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: Some(Line::from("Status line content".to_string()).into()),
status_line_enabled: true,
@@ -1555,7 +1540,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: true,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None, // command timed out / empty
status_line_enabled: true,
@@ -1585,7 +1569,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: true,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: false,
@@ -1607,7 +1590,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: false,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: true,
@@ -1630,7 +1612,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: true,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: Some(
Line::from(
@@ -1658,7 +1639,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: false,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: false,
@@ -1674,7 +1654,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: false,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: Some(Line::from("Status line content".to_string()).into()),
status_line_enabled: true,
@@ -1693,7 +1672,6 @@ mod tests {
is_task_running: false,
queue_submissions: false,
collaboration_modes_enabled: true,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: Some(Line::from(
"Status line content that is definitely too long to fit alongside the mode label"
@@ -11,6 +11,7 @@ use crate::key_hint;
use crate::key_hint::KeyBinding;
use crate::key_hint::ShortcutHint;
use crate::keymap::KeymapContext;
use crate::keymap::KeymapContextSet;
use crate::keymap::RuntimeKeymap;
use crate::keymap::bindings_for_action;
use crate::multi_agents::next_agent_shortcut;
@@ -34,36 +35,43 @@ use ratatui::widgets::Paragraph;
use ratatui::widgets::Widget;
use std::collections::HashMap;
/// The view switch takes the first free key. Layer browsing uses the next one.
/// Guide shortcuts selected from keys available in the current composer.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) struct ShortcutGuideKeys {
view: Option<KeyCode>,
layer: Option<KeyCode>,
paste_image: Option<ShortcutHint>,
}
impl ShortcutGuideKeys {
pub(super) fn from_keymap(keymap: &RuntimeKeymap) -> Self {
pub(super) fn from_keymap(keymap: &RuntimeKeymap, paste_image: KeyBinding) -> Self {
let conflicts = |context: KeymapContext| {
context == KeymapContext::Pager || context.overlaps(KeymapContext::Composer)
};
let mut free =
std::iter::once(KeyCode::Tab)
.chain((1..=12).map(KeyCode::F))
.filter(|&code| {
let key = key_hint::plain(code);
// The guide opens on an empty draft, so queue has nothing to send.
!crate::keymap::keymap_action_ids().any(|id| {
conflicts(id.context)
&& (id.context != KeymapContext::Composer || id.action != "queue")
&& bindings_for_action(keymap, id.context.config_name(), id.action)
.is_some_and(|bindings| bindings.contains(&key))
}) && !keymap.chords.bindings.iter().any(|binding| {
conflicts(binding.action.context) && binding.chord.prefix == key
})
});
let is_free = |key| {
// The guide opens on an empty draft, so queue has nothing to send.
!crate::keymap::keymap_action_ids().any(|id| {
conflicts(id.context)
&& (id.context != KeymapContext::Composer || id.action != "queue")
&& bindings_for_action(keymap, id.context.config_name(), id.action)
.is_some_and(|bindings| bindings.contains(&key))
}) && !keymap
.chords
.bindings
.iter()
.any(|binding| conflicts(binding.action.context) && binding.chord.prefix == key)
};
let mut free = std::iter::once(KeyCode::Tab)
.chain((1..=12).map(KeyCode::F))
.filter(|&code| is_free(key_hint::plain(code)));
let (code, modifiers) = paste_image.parts();
let composer = KeymapContextSet::new(KeymapContext::Composer).with(KeymapContext::Editor);
Self {
view: free.next(),
layer: free.next(),
paste_image: keymap
.allows_image_paste(KeyEvent::new(code, modifiers), composer)
.then_some(paste_image.into()),
}
}
}
@@ -184,11 +192,6 @@ impl Entry {
fn bindings(props: &FooterProps) -> [(&'static str, Vec<Entry>); 3] {
use KeyCode as K;
let hints = props.key_hints;
let paste = if props.is_wsl {
key_hint::ctrl_alt(K::Char('v'))
} else {
key_hint::ctrl(K::Char('v'))
};
let edit_previous = match hints.edit_previous {
Some(ShortcutHint::Single(key)) if !props.esc_backtrack_hint => Some(ShortcutHint::Chord {
prefix: key,
@@ -201,7 +204,7 @@ fn bindings(props: &FooterProps) -> [(&'static str, Vec<Entry>); 3] {
Entry::key(key_hint::plain(K::Char('@')), "Mention files"),
Entry::key(key_hint::plain(K::Char('!')), "Shell command"),
Entry::hint(hints.insert_newline, "New line"),
Entry::key(paste, "Paste image"),
Entry::hint(hints.shortcut_guide.paste_image, "Paste image"),
Entry::hint(hints.external_editor, "External editor"),
Entry::hint(hints.history_search, "Search history"),
Entry::hint(edit_previous, "Edit last message"),
@@ -25,7 +25,6 @@ fn props() -> FooterProps {
is_task_running: true,
queue_submissions: false,
collaboration_modes_enabled: true,
is_wsl: false,
quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
status_line_value: None,
status_line_enabled: false,
@@ -77,7 +76,10 @@ fn snapshot(name: &str, width: u16, height: Option<u16>, props: &FooterProps) {
fn shortcut_overlay_uses_runtime_bindings_and_wsl_paste() {
let mut props = props();
props.is_task_running = false;
props.is_wsl = true;
let paste = key_hint::alt(KeyCode::Char('v'));
let config = toml::from_str(r#"pager.mark_markdown = "alt-v""#).unwrap();
let keymap = crate::keymap::RuntimeKeymap::from_config(&config).unwrap();
props.key_hints.shortcut_guide = ShortcutGuideKeys::from_keymap(&keymap, paste);
props.esc_backtrack_hint = true;
props.key_hints.external_editor = Some(ShortcutHint::Chord {
prefix: key_hint::ctrl(KeyCode::Char('x')),
@@ -106,6 +108,40 @@ fn shortcut_overlay_uses_runtime_bindings_and_wsl_paste() {
/*height*/ None,
&props,
);
props.mode = FooterMode::ShortcutOverlay(ShortcutView::List);
for queue in ["alt-v", "alt-v q"] {
let config = toml::from_str(&format!(r#"composer.queue = "{queue}""#)).unwrap();
let keymap = crate::keymap::RuntimeKeymap::from_config(&config).unwrap();
let hint = keymap
.primary_hint(crate::keymap::KeymapContext::Composer, "queue")
.unwrap();
props.key_hints.queue = Some(hint);
props.key_hints.shortcut_guide = ShortcutGuideKeys::from_keymap(&keymap, paste);
let guide = ratatui::text::Text::from(lines(&props, /*width*/ 80)).to_string();
assert!(
guide
.lines()
.any(|row| row.contains(&hint.display_label()) && row.contains("Send message"))
);
assert!(!guide.contains("Paste image"));
}
let config = toml::from_str(
r#"
global.copy = "alt-v"
pager.mark_markdown = "ctrl-v"
"#,
)
.unwrap();
let keymap = crate::keymap::RuntimeKeymap::from_config(&config).unwrap();
props.key_hints.shortcut_guide = ShortcutGuideKeys::from_keymap(&keymap, paste);
let guide = ratatui::text::Text::from(lines(&props, /*width*/ 80)).to_string();
assert!(!guide.contains("Paste image"));
let ctrl_v = key_hint::ctrl(KeyCode::Char('v'));
assert_eq!(
ShortcutGuideKeys::from_keymap(&keymap, ctrl_v).paste_image,
Some(ctrl_v.into())
);
}
#[test]
@@ -120,7 +156,8 @@ fn shortcut_overlay_leaves_remapped_tab_and_function_keys_available() {
.unwrap();
let keymap = crate::keymap::RuntimeKeymap::from_config(&config).unwrap();
let mut props = props();
props.key_hints.shortcut_guide = ShortcutGuideKeys::from_keymap(&keymap);
props.key_hints.shortcut_guide =
ShortcutGuideKeys::from_keymap(&keymap, key_hint::ctrl(KeyCode::Char('v')));
let mut view = ShortcutView::List;
let keys = props.key_hints.shortcut_guide;
@@ -9,7 +9,7 @@ expression: terminal.backend()
" @ Mention files ⇧tab Change mode "
" ! Shell command ⌥. More reasoning "
" ⇧enter New line f8 Voice "
" ⌃⌥v Paste image ← Agents (empty prompt) "
" ⌥v Paste image ← Agents (empty prompt) "
" ⌃x ⌃e External editor ⌥← / ⌥→ Subagents (empty prompt) "
" esc Edit last message ⌃5 Inspect activity "
" ⌃c Quit "
+5 -1
View File
@@ -114,7 +114,11 @@ impl ChatWidget {
&& ((matches!(key.code, KeyCode::Char(c) if c.eq_ignore_ascii_case(&'v'))
&& key
.modifiers
.intersects(KeyModifiers::CONTROL | KeyModifiers::ALT))
.intersects(KeyModifiers::CONTROL | KeyModifiers::ALT)
&& self
.bottom_pane
.keymap()
.allows_image_paste(key, self.keymap_contexts()))
|| shift_insert);
if !image_paste {
if matches!(key.kind, KeyEventKind::Press | KeyEventKind::Release) {
@@ -123,6 +123,41 @@ async fn reconnect_queues_enter_and_resumes_ordinary_next_turn_submission() {
assert_eq!(sequence, ["prompt", "submit"]);
}
#[tokio::test]
async fn alt_v_pastes_with_a_pager_remap_but_sends_with_a_queue_remap() {
let (mut chat, _events, mut operations) = make_chatwidget_manual(/*model_override*/ None).await;
chat.thread_id = Some(ThreadId::new());
let alt_v = KeyEvent::new(KeyCode::Char('v'), KeyModifiers::ALT);
let config = toml::from_str(r#"pager.mark_markdown = "alt-v""#).unwrap();
let keymap = RuntimeKeymap::from_config(&config).unwrap();
chat.apply_keymap_update(config, &keymap);
chat.apply_external_edit("draft".into());
assert_matches!(
chat.handle_key_event(alt_v),
KeyEventAction::PasteImage { .. }
);
let config = toml::from_str(r#"composer.queue = "alt-v""#).unwrap();
let keymap = RuntimeKeymap::from_config(&config).unwrap();
chat.apply_keymap_update(config, &keymap);
assert_matches!(chat.handle_key_event(alt_v), KeyEventAction::None);
let Op::UserTurn { items, .. } = next_submit_op(&mut operations) else {
panic!("expected the existing draft to be submitted");
};
assert_eq!(
items,
vec![UserInput::Text {
text: "draft".into(),
text_elements: Vec::new(),
}]
);
chat.on_task_started();
chat.apply_external_edit("next".into());
assert_matches!(chat.handle_key_event(alt_v), KeyEventAction::None);
assert_eq!(chat.queued_user_message_texts(), ["next"]);
}
#[tokio::test]
async fn composer_submission_sends_once_and_requests_latest() {
let (mut chat, mut events, mut operations) =
+50 -4
View File
@@ -253,14 +253,60 @@ fn try_wsl_clipboard_fallback(
}
tracing::debug!("attempting Windows PowerShell clipboard fallback");
// WinForms can read bitmaps in both Windows PowerShell 5.1 and PowerShell 7.
// Return bytes so no Windows temp files are needed, even for a rejected paste.
let script = r#"$img = Get-Clipboard -Format Image; if ($null -eq $img) { exit 1 }; $png = New-Object System.IO.MemoryStream; $img.Save($png, [System.Drawing.Imaging.ImageFormat]::Png); if ($png.Length -gt 1GB) { exit 1 }; $png.WriteTo([Console]::OpenStandardOutput())"#;
let script = r#"
$ErrorActionPreference = 'Stop'
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$img = [System.Windows.Forms.Clipboard]::GetImage()
if ($null -eq $img) { exit 1 }
$png = New-Object System.IO.MemoryStream
$img.Save($png, [System.Drawing.Imaging.ImageFormat]::Png)
if ($png.Length -gt 1GB) { exit 1 }
$png.WriteTo([Console]::OpenStandardOutput())
"#;
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?;
for cmd in ["powershell.exe", "pwsh", "powershell"] {
let mut command = crate::command_output::wsl_command(Path::new(cmd));
command.args(["-NoProfile", "-Command", script]);
let on_path = ["powershell.exe", "pwsh", "powershell", "pwsh.exe"]
.into_iter()
.map(|name| crate::command_output::wsl_command(Path::new(name)));
// With Windows PATH import disabled, resolve the installed engines in the child
// so even drive translation and executable lookup share the paste deadline.
let installed = [
"Windows/System32/WindowsPowerShell/v1.0/powershell.exe",
"Program Files/PowerShell/7/pwsh.exe",
]
.into_iter()
.map(|location| {
let mut command = crate::command_output::wsl_command(Path::new("/bin/sh"));
command.args([
"-c",
r#"
if [ -x /bin/wslpath ]; then
drive=$(/bin/wslpath -u 'C:\') || exit 1
else
/usr/bin/mountpoint -q /mnt/c || exit 1
drive=/mnt/c
fi
case "$drive" in /*) ;; *) exit 1 ;; esac
exe="${drive%/}/$1"
shift
[ "$exe" -ef "$(command -v "${exe##*/}")" ] && exit 1
exec "$exe" "$@"
"#,
"codex-wsl-image",
location,
]);
command
});
for mut command in on_path.chain(installed) {
// Avoid workspace-relative assembly loads and excessively long WSL working directories.
command
.current_dir("/")
.args(["-NoProfile", "-Command", script]);
let Some(output) = runtime.block_on(wsl_image::read_command(
command,
deadline,
+15
View File
@@ -713,6 +713,21 @@ impl RuntimeKeymap {
}
}
/// Ctrl paste is reserved. Alt paste yields to any active binding or chord prefix.
pub(crate) fn allows_image_paste(&self, event: KeyEvent, contexts: KeymapContextSet) -> bool {
if event.modifiers.contains(KeyModifiers::CONTROL) {
return true;
}
let contexts = contexts
.with(KeymapContext::Global)
.with(KeymapContext::Chat);
!self.has_single_binding(event, contexts)
&& !self.chords.bindings.iter().any(|binding| {
contexts.contains_action(binding.action)
&& chord_stroke_matches(binding.chord.prefix, event)
})
}
pub(crate) fn has_single_binding(&self, event: KeyEvent, contexts: KeymapContextSet) -> bool {
runtime_action_bindings(self)
.any(|action| contexts.contains_action(action.id) && action.bindings.is_pressed(event))
+20
View File
@@ -236,6 +236,26 @@ impl ClipboardCapabilities {
}
}
/// Prefer Alt+V if Windows-hosted VS Code might consume Ctrl+Alt+V as AltGr.
pub(crate) fn image_paste_shortcut() -> crate::key_hint::KeyBinding {
image_paste_shortcut_for(is_wsl_session().then(keyboard_modes::detect_vscode_terminal))
}
fn image_paste_shortcut_for(
wsl_host: Option<keyboard_modes::VscodeDetection>,
) -> crate::key_hint::KeyBinding {
use crate::key_hint;
use crossterm::event::KeyCode;
use keyboard_modes::VscodeDetection;
let key = KeyCode::Char('v');
match wsl_host {
None => key_hint::ctrl(key),
Some(VscodeDetection::Other) => key_hint::ctrl_alt(key),
Some(VscodeDetection::VsCode | VscodeDetection::Unknown) => key_hint::alt(key),
}
}
pub(crate) fn forwards_copy_shortcut() -> bool {
forwards_copy_shortcut_for(&terminal_info())
}
@@ -33,3 +33,20 @@ fn live_palette_requires_a_supported_direct_local_terminal() {
);
}
}
#[test]
fn wsl_image_hint_avoids_altgr_when_the_terminal_probe_is_inconclusive() {
use super::keyboard_modes::VscodeDetection;
use crate::key_hint;
use crossterm::event::KeyCode;
let key = KeyCode::Char('v');
for (host, hint) in [
(None, key_hint::ctrl(key)),
(Some(VscodeDetection::Other), key_hint::ctrl_alt(key)),
(Some(VscodeDetection::VsCode), key_hint::alt(key)),
(Some(VscodeDetection::Unknown), key_hint::alt(key)),
] {
assert_eq!(super::image_paste_shortcut_for(host), hint, "{host:?}");
}
}