Files
codex/codex-rs/tui/src/chatwidget/clipboard.rs
T
Eric Traut a9b0815167 Support Windows clipboard text paste shortcuts in the TUI (#53224)
## Why

`Ctrl+V` previously attempted only image paste, so a text-only clipboard produced an image-paste error. `Shift+Insert` did not use the clipboard paste path.

## What changed

- On Windows, let `Ctrl+V` and `Shift+Insert` paste images first, then read clipboard text asynchronously when no image is available. Keep clipboard access errors distinct from missing images.
- Allow keyboard paste into composer selections and active history or Vim search queries, including inline mode with right-click paste disabled.
- Flush buffered typing before explicit paste to preserve input order. Discard pending clipboard text when the thread or editable target changes, while allowing shortcut releases and repeated paste shortcuts to leave the read pending.

## Testing

Extend shortcut and clipboard-worker tests to cover text fallback, multiline Unicode text, stale-read cancellation, shortcut releases and repeats, and read-only drafts. Add assertions for history-search preview stability and selection changes.

GitOrigin-RevId: 080c1c05a4587e325cea938a6e28c646b9ac5837
2026-10-11 23:44:43 +00:00

61 lines
2.2 KiB
Rust

//! Handle clipboard feedback and image paste after the app checks worker availability.
//! Pending feedback belongs to this widget, so switching conversations discards it.
use super::*;
use crate::clipboard_copy::worker::CopyResult;
pub(super) const IMAGE_PASTE_REPEAT_WINDOW: Duration = Duration::from_millis(/*millis*/ 250);
pub(super) enum PendingCopy {
Message(u64, String),
Selection(u64),
}
impl ChatWidget {
pub(crate) fn paste_image(&mut self) -> Result<(), crate::clipboard_paste::PasteImageError> {
let result = paste_image_to_temp_png();
self.suppress_image_paste_until = Instant::now() + IMAGE_PASTE_REPEAT_WINDOW;
let (path, info) = result?;
tracing::debug!(
"pasted image size={}x{} format={}",
info.width,
info.height,
info.encoded_format.label()
);
self.attach_image(path);
Ok(())
}
pub(super) fn show_clipboard_flash(&mut self, result: &CopyResult) {
let line = match result {
Ok(status) => Line::from(status.message("selection").dim()),
Err(error) => Line::from(format!("Copy failed: {error}").red()),
};
self.bottom_pane
.show_footer_flash(line, Duration::from_secs(/*secs*/ 3));
}
pub(crate) fn finish_clipboard(
&mut self,
completion: &(u64, CopyResult),
composer_visible: bool,
) -> Option<usize> {
let pending_id = match &self.pending_clipboard {
Some(PendingCopy::Message(id, _) | PendingCopy::Selection(id)) => Some(*id),
None => None,
};
if pending_id == Some(completion.0) {
match self.pending_clipboard.take() {
Some(PendingCopy::Message(_, label)) => match &completion.1 {
Ok(status) => self.add_info_message(status.message(&label), /*hint*/ None),
Err(error) => self.add_error_message(format!("Copy failed: {error}")),
},
Some(PendingCopy::Selection(_)) => self.show_clipboard_flash(&completion.1),
None => {}
}
}
self.bottom_pane
.finish_composer_copy(completion, composer_visible)
}
}