Share composer copy handling across keyboard and mouse input (#65107)

## What changed

- Route keyboard and mouse copies of composer selections through the same
  plain-text copy helper.
- Check composer visibility separately when completing clipboard work
  and canceling primary selection. Use the overlay input check when
  deciding whether to end a composer drag.
- Convert external transcript links to view actions through the shared
  `ReaderLink` conversion.

GitOrigin-RevId: 7285acfe6d8911da806adbba7da8b79393389b08
This commit is contained in:
Felipe Coury
2026-12-01 23:13:10 +00:00
committed by copyberry
parent 80d0a67185
commit fbb04fca5f
4 changed files with 25 additions and 21 deletions
+1 -5
View File
@@ -1055,11 +1055,7 @@ impl App {
{
return Ok(AppRunControl::Continue);
}
if matches!(&event, TuiEvent::Key(_))
&& self.handle_composer_copy_event(tui, &event, |tui, text| {
tui.copy_transcript_selection(text, crate::clipboard_copy::CopyFormat::PlainText)
})
{
if matches!(&event, TuiEvent::Key(_)) && self.copy_composer_selection(tui, &event) {
return Ok(AppRunControl::Continue);
}
if matches!(&event, TuiEvent::Resize(_) | TuiEvent::Resume) {
+10 -3
View File
@@ -62,8 +62,12 @@ impl App {
self.chat_widget
.finish_image_paste(event, self.overlay.is_none());
let current = tui.is_owned_screen() && self.overlay.is_none();
let composer_visible = current;
if let Some(completion) = tui.clipboard.poll() {
if let Some(characters) = self.chat_widget.finish_clipboard(completion, current) {
if let Some(characters) = self
.chat_widget
.finish_clipboard(completion, composer_visible)
{
self.transcript_view
.show_copy_feedback(&completion.1, characters);
}
@@ -109,7 +113,11 @@ impl App {
self.backtrack.select_exit_key = pending_exit_key;
}
}
if !current || matches!(event, TuiEvent::FocusLost | TuiEvent::Resume) {
let reset = matches!(event, TuiEvent::FocusLost | TuiEvent::Resume);
if !composer_visible || reset {
self.chat_widget.cancel_composer_primary();
}
if !current || reset {
self.transcript_view.cancel_primary();
for companion in self.side_companions.values_mut() {
companion.view.cancel_primary();
@@ -117,7 +125,6 @@ impl App {
for pane in self.sidebars.values_mut() {
pane.cancel_hidden_document_primary(/*visible*/ false);
}
self.chat_widget.cancel_composer_primary();
self.chat_widget
.rendered_selection
.borrow_mut()
+12 -12
View File
@@ -175,15 +175,22 @@ impl App {
}
/// Copy draft selections before key shortcuts, or after mouse layout has been refreshed.
pub(super) fn handle_composer_copy_event(
pub(super) fn copy_composer_selection(&mut self, tui: &mut tui::Tui, event: &TuiEvent) -> bool {
self.handle_composer_copy_event(tui, event, |tui, text| {
tui.copy_transcript_selection(text, crate::clipboard_copy::CopyFormat::PlainText)
})
}
fn handle_composer_copy_event(
&mut self,
tui: &mut tui::Tui,
event: &TuiEvent,
copy: impl FnOnce(&mut tui::Tui, &str) -> Result<crate::clipboard_copy::CopyStatus, String>,
) -> bool {
if tui.is_owned_screen()
let can_copy = tui.is_owned_screen()
&& self.overlay.is_none()
&& !self.transcript_view.has_active_interaction()
&& !self.transcript_view.has_active_interaction();
if can_copy
&& let Some((char_count, result)) = self
.chat_widget
.copy_composer_selection(event, |text| copy(tui, text))
@@ -1315,7 +1322,7 @@ impl App {
}
if !tui.is_owned_screen()
|| matches!(event, TuiEvent::FocusLost | TuiEvent::Resume)
|| self.overlay.is_some()
|| self.overlay_owns_input()
{
self.chat_widget.end_composer_drag();
}
@@ -1406,14 +1413,7 @@ impl App {
tui.frame_requester().schedule_frame();
return Ok(true);
}
if composer_ready
&& self.handle_composer_copy_event(tui, event, |tui, text| {
tui.copy_transcript_selection(
text,
crate::clipboard_copy::CopyFormat::PlainText,
)
})
{
if composer_ready && self.copy_composer_selection(tui, event) {
return Ok(true);
}
if composer_ready && self.chat_widget.handle_composer_mouse(*mouse) {
+2 -1
View File
@@ -440,7 +440,8 @@ impl TranscriptView {
.iter()
.find(|link| link.columns.contains(&column))?
.interaction_destination()
.map(ViewAction::OpenLink);
.map(ReaderLink::External)
.map(ViewAction::from);
}
let inside = self.area.contains(point);
let dragging = self