mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
## Why Terminal checks for clipboard behavior are spread across the clipboard worker, local settings, and right-click paste handling. ## What changed Use `terminal_capabilities` to determine whether the terminal forwards copy shortcuts or handles paste itself, whether X11 primary selection is available, and how to send OSC 52 through tmux or GNU Screen. Have TUI callers use the same SSH and WSL session checks. Keep the automatic copy-on-select decision in settings and base it on whether the terminal forwards the copy shortcut. Route tmux clipboard copies through the client buffer with OSC 52 as a fallback. GitOrigin-RevId: 623599783b70d66a06c52458fc82305a422cf507
83 lines
3.4 KiB
Rust
83 lines
3.4 KiB
Rust
//! Route registered read-only selections before copy, interrupt, clicks, and paste shortcuts.
|
|
//! A stationary click is replayed to the existing widget handler after selection releases it.
|
|
|
|
use super::*;
|
|
use crate::clipboard_copy::CopyFormat;
|
|
use crate::keymap::ListAction;
|
|
use crate::rendered_selection::RegionAction;
|
|
use crate::rendered_selection::RenderedSelection;
|
|
use crate::transcript_view::ViewAction;
|
|
|
|
impl App {
|
|
pub(super) fn handle_rendered_selection_event(
|
|
&mut self,
|
|
tui: &mut tui::Tui,
|
|
event: &TuiEvent,
|
|
) -> Result<bool> {
|
|
let warning_active = self.chat_widget.keymap_contexts().is_warnings();
|
|
if !tui.is_owned_screen()
|
|
|| self.overlay.is_some()
|
|
|| (!warning_active
|
|
&& (!self.chat_widget.no_modal_or_popup_active()
|
|
|| self.chat_widget.is_external_writer_view()))
|
|
{
|
|
*self.chat_widget.rendered_selection.borrow_mut() = RenderedSelection::default();
|
|
return Ok(false);
|
|
}
|
|
let refresh = matches!(event, TuiEvent::Mouse(mouse)
|
|
if self.chat_widget.rendered_selection.borrow().needs_refresh(*mouse));
|
|
if refresh {
|
|
self.refresh_owned_transcript(tui)?;
|
|
}
|
|
let action = {
|
|
let mut selection = self.chat_widget.rendered_selection.borrow_mut();
|
|
if warning_active
|
|
&& let TuiEvent::Key(key) = event
|
|
&& matches!(
|
|
self.keymap.list.action_for(*key),
|
|
Some(ListAction::PageUp | ListAction::PageDown)
|
|
)
|
|
{
|
|
selection.clear();
|
|
return Ok(false);
|
|
}
|
|
selection.view.copy_on_select = self.local_settings.copy_on_select();
|
|
selection.view.copy_on_select_clear_selection =
|
|
self.local_settings.tui.copy_on_select_clear_selection;
|
|
selection.view.primary_selection = self.right_click_paste_environment.primary;
|
|
selection.handle_event(event, tui.terminal.previous_buffer())
|
|
};
|
|
let Some(action) = action else {
|
|
return Ok(false);
|
|
};
|
|
if warning_active {
|
|
self.chat_widget.record_warning_activity();
|
|
}
|
|
self.cancel_pending_key_chord();
|
|
match action {
|
|
RegionAction::Click(mouse) => {
|
|
self.chat_widget
|
|
.handle_warning_event(&TuiEvent::Mouse(mouse), &self.transcript_cells);
|
|
}
|
|
RegionAction::Selection(action) => {
|
|
self.transcript_view.end_selection(&self.transcript_cells);
|
|
self.transcript_view.cancel_search();
|
|
self.transcript_view.clear_activity_focus();
|
|
self.chat_widget.clear_composer_selection();
|
|
let copied = {
|
|
let mut selection = self.chat_widget.rendered_selection.borrow_mut();
|
|
let RenderedSelection { view, cells, .. } = &mut *selection;
|
|
view.copy_action(tui, cells, &action, CopyFormat::PlainText)
|
|
};
|
|
if let Some((characters, result)) = copied {
|
|
self.transcript_view.show_copy_feedback(&result, characters);
|
|
} else if let ViewAction::OpenLink(url) = action {
|
|
self.open_url_in_browser(url);
|
|
}
|
|
}
|
|
}
|
|
tui.frame_requester().schedule_frame();
|
|
Ok(true)
|
|
}
|
|
}
|