feat(tui): add paste shortcuts fallback to read raw image from clipboard

Terminals like iTerm2 do not emit  for non-text clipboards. When
users press common paste keys (Ctrl+V, Ctrl+Shift+V, Shift+Insert), dispatch an
empty paste to the composer. The composer already treats empty paste as a cue to
attempt  via arboard+image and attach the PNG path.

This keeps normal text paste behavior (Cmd+V still triggers Event::Paste) and
adds a sensible fallback for image-only clipboards.
This commit is contained in:
James Peter
2025-09-01 20:18:22 +10:00
parent d4287d2fbc
commit 7c32e8e134
+31
View File
@@ -420,6 +420,37 @@ impl App<'_> {
}
// Otherwise fall through
}
// Fallback: attempt clipboard image paste on common shortcuts.
// Many terminals (e.g., iTerm2) do not emit Event::Paste for raw-image
// clipboards. When the user presses paste shortcuts, try an image read
// by dispatching a paste with an empty string. The composer will then
// attempt `paste_image_to_temp_png()` and no-op if no image exists.
KeyEvent {
code: KeyCode::Char('v'),
modifiers: crossterm::event::KeyModifiers::CONTROL,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
} => {
self.dispatch_paste_event(String::new());
}
KeyEvent {
code: KeyCode::Char('v'),
modifiers: m,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
} if m.contains(crossterm::event::KeyModifiers::CONTROL)
&& m.contains(crossterm::event::KeyModifiers::SHIFT) =>
{
self.dispatch_paste_event(String::new());
}
KeyEvent {
code: KeyCode::Insert,
modifiers: crossterm::event::KeyModifiers::SHIFT,
kind: KeyEventKind::Press | KeyEventKind::Repeat,
..
} => {
self.dispatch_paste_event(String::new());
}
KeyEvent {
code: KeyCode::Char('m'),
modifiers: crossterm::event::KeyModifiers::CONTROL,