Keep the TUI responsive during clipboard copies (#47847)

## Why

Native clipboard setup and writes can block, preventing the TUI from processing input or closing overlays while a copy is in progress.

## What changed

- Route clipboard copies through one session worker that retains native clipboard ownership. Keep terminal escape output on the UI thread.
- Show pending and busy status messages, reject additional copies without queuing them, and ask users to retry image paste after an active copy finishes.
- Abandon setup after five seconds and prevent late delivery. Keep the worker busy until the blocked call returns, and bound shutdown waiting for clipboard handoff.
- Match completions to their originating requests so stale results cannot clear newer selections or unexpectedly resume transcript following. Retain selections on automatic copies, failures, and unconfirmed delivery.

## Testing

Add regression tests for blocked backends, overlay exit, copy and paste ordering, setup expiry, bounded shutdown, completion status messages, and preservation of replaced or moved selections.

GitOrigin-RevId: 4ba1f8da258b9d0700b0edec9ac0ba699f536785
This commit is contained in:
Felipe Coury
2026-09-24 14:15:42 +00:00
committed by copyberry
parent 282cd7b019
commit 12fd929f72
38 changed files with 1238 additions and 444 deletions
@@ -5,19 +5,6 @@ use crate::app_event::TranscriptExportDestination;
use crate::bottom_pane::popup_consts::picker_hint_line_for_keymap;
impl ChatWidget {
pub(crate) fn copy_transcript_to_clipboard(&mut self, markdown: &str) {
match crate::clipboard_copy::copy_to_clipboard(
markdown,
crate::clipboard_copy::CopyFormat::PlainText,
) {
Ok(outcome) => {
let status = outcome.store(&mut self.clipboard_lease);
self.add_info_message(status.message("conversation"), /*hint*/ None);
}
Err(error) => self.add_error_message(format!("Copy failed: {error}")),
}
}
pub(super) fn show_transcript_export_popup(&mut self) {
self.show_selection_view(SelectionViewParams {
header: Box::new(