Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions codex-rs/config/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,14 +777,14 @@ pub enum RightClickPaste {
Off,
}

/// When transcript mouse selections are copied on release.
/// When mouse selections are copied on release.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, Default)]
#[serde(rename_all = "lowercase")]
pub enum CopyOnSelect {
/// Use the terminal-specific default.
#[default]
Auto,
/// Copy every nonempty transcript mouse selection on release.
/// Copy every nonempty transcript or footer mouse selection on release.
Always,
/// Require an explicit copy action.
Never,
Expand Down Expand Up @@ -889,7 +889,7 @@ pub struct Tui {
#[schemars(schema_with = "crate::tui_mouse_scroll::schema")]
pub mouse_scroll_speed: Option<f64>,

/// Copy selected transcript text when the mouse button is released.
/// Copy selected transcript or footer text when the mouse button is released.
/// Defaults to `auto`: enabled except in direct terminals known to forward their native
/// copy shortcut (Ghostty 1.2+, Kitty on macOS, Windows Terminal, and VS Code on Windows).
/// Unknown terminals, Ghostty without a recognized version, and tmux/Zellij default to copying.
Expand Down
6 changes: 3 additions & 3 deletions codex-rs/core/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@
"type": "object"
},
"CopyOnSelect": {
"description": "When transcript mouse selections are copied on release.",
"description": "When mouse selections are copied on release.",
"oneOf": [
{
"description": "Use the terminal-specific default.",
Expand All @@ -1392,7 +1392,7 @@
"type": "string"
},
{
"description": "Copy every nonempty transcript mouse selection on release.",
"description": "Copy every nonempty transcript or footer mouse selection on release.",
"enum": [
"always"
],
Expand Down Expand Up @@ -4611,7 +4611,7 @@
}
],
"default": "auto",
"description": "Copy selected transcript text when the mouse button is released. Defaults to `auto`: enabled except in direct terminals known to forward their native copy shortcut (Ghostty 1.2+, Kitty on macOS, Windows Terminal, and VS Code on Windows). Unknown terminals, Ghostty without a recognized version, and tmux/Zellij default to copying."
"description": "Copy selected transcript or footer text when the mouse button is released. Defaults to `auto`: enabled except in direct terminals known to forward their native copy shortcut (Ghostty 1.2+, Kitty on macOS, Windows Terminal, and VS Code on Windows). Unknown terminals, Ghostty without a recognized version, and tmux/Zellij default to copying."
},
"disable_paste_burst": {
"description": "When true, disables burst-paste detection for typed input entirely. All characters are inserted as they are received, and no buffering or placeholder replacement will occur for fast keypress bursts. Overrides the legacy top-level `disable_paste_burst` setting. Defaults to `false`.",
Expand Down
4 changes: 4 additions & 0 deletions codex-rs/tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ mod new_session;
mod turn_tips;
pub(crate) use new_session::has_launch_setting;
mod clipboard;
mod footer_selection;
mod native_history;
mod owned_transcript;
mod pending_interactive_replay;
Expand Down Expand Up @@ -855,6 +856,9 @@ impl App {
self.finish_clipboard(tui, &event);
let event = self.finish_right_click_paste(tui, event);
let idle_draw = matches!(event, TuiEvent::Draw);
if self.handle_rendered_selection_event(tui, &event)? {
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)
Expand Down
6 changes: 6 additions & 0 deletions codex-rs/tui/src/app/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ impl App {
self.transcript_view
.show_copy_feedback(&completion.1, characters);
}
{
let mut selection = self.chat_widget.rendered_selection.borrow_mut();
let crate::rendered_selection::RenderedSelection { view, cells, .. } =
&mut *selection;
view.finish_copy(cells, completion, current);
}
let follow =
self.transcript_view
.finish_copy(&self.transcript_cells, completion, current);
Expand Down
67 changes: 67 additions & 0 deletions codex-rs/tui/src/app/footer_selection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//! 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::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> {
if !tui.is_owned_screen()
|| self.overlay.is_some()
|| !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 {
let size = tui.prepare_draw_size()?;
self.render_owned_transcript(tui, size)?;
}
let action = {
let mut selection = self.chat_widget.rendered_selection.borrow_mut();
selection.view.copy_on_select = self
.local_settings
.copy_on_select(&codex_terminal_detection::terminal_info());
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);
};
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)
}
}
1 change: 1 addition & 0 deletions codex-rs/tui/src/app/history_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ impl App {
self.native_history = Default::default();
self.cancel_pending_key_chord();
self.transcript_view = Default::default();
*self.chat_widget.rendered_selection.borrow_mut() = Default::default();
self.last_rendered_history_tail = None;
self.last_thread_usage_status_cell = None;
self.pending_thread_usage_history_refresh = false;
Expand Down
51 changes: 29 additions & 22 deletions codex-rs/tui/src/app/owned_transcript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,21 @@ impl App {
};
self.sync_owned_transcript(screen_size.width);
let transcript_width = self.chat_widget.history_wrap_width(screen_size.width);
let composer_hint = self.composer_hint(transcript_width);
let composer_hint = if self
.chat_widget
.rendered_selection
.borrow()
.view
.has_active_interaction()
{
Some(
ratatui::text::Line::from("Selecting footer · esc cancel")
.dim()
.into(),
)
} else {
self.composer_hint(transcript_width)
};
let now = Instant::now();
let turn_tip = self.turn_tip(transcript_width, now, &tui.frame_requester());
let working_tip = turn_tip
Expand Down Expand Up @@ -160,6 +174,7 @@ impl App {
let mut blossom_tick = None;
let mut transcript_bottom = available.saturating_sub(u16::from(composer_gap.is_none()));
tui.draw(screen_size.height, |frame| {
chat_widget.rendered_selection.borrow_mut().areas.clear();
ratatui::widgets::Clear.render(
Rect::new(/*x*/ 0, /*y*/ 0, screen_size.width, available),
frame.buffer,
Expand Down Expand Up @@ -270,6 +285,10 @@ impl App {
.filter(|_| chat_widget.no_modal_or_popup_active());
feedback_tick =
view.render_composer_gap(follow_area, composer_hint.as_ref(), frame.buffer, now);
chat_widget
.rendered_selection
.borrow_mut()
.render(frame.buffer);
chat_widget.note_rendered_width(screen_size.width);
let dialog = chat_widget.centered_dialog();
let (foreground, foreground_area): (&dyn Renderable, Rect) =
Expand Down Expand Up @@ -576,27 +595,15 @@ impl App {
}
return self.handle_owned_backtrack_event(tui, event);
};
let resume_following = matches!(action, ViewAction::CopyAndFollow(_));
let copy_on_select = matches!(action, ViewAction::CopyOnSelect(_));
match action {
ViewAction::Changed => {}
ViewAction::PrimarySelection(text) => self.transcript_view.publish_primary(tui, &text),
ViewAction::Copy(text)
| ViewAction::CopyOnSelect(text)
| ViewAction::CopyAndFollow(text) => {
let result = self.transcript_view.copy_selected_text(
tui,
&self.transcript_cells,
&text,
!copy_on_select,
);
if resume_following
&& matches!(result, Ok(crate::clipboard_copy::CopyStatus::Pending(_)))
{
self.transcript_view.follow_pending_copy();
}
}
ViewAction::OpenLink(url) => self.open_url_in_browser(url),
if let Some((characters, result)) = self.transcript_view.copy_action(
tui,
&self.transcript_cells,
&action,
crate::clipboard_copy::CopyFormat::Markdown,
) {
self.transcript_view.show_copy_feedback(&result, characters);
} else if let ViewAction::OpenLink(url) = action {
self.open_url_in_browser(url);
}
self.request_owned_history(tui, app_server);
tui.frame_requester().schedule_frame();
Expand Down
66 changes: 66 additions & 0 deletions codex-rs/tui/src/app/owned_transcript_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,72 @@ async fn fullscreen_composer_remote_images_leave_an_editable_prompt_row() -> Res
"fullscreen_prompt_remote_images",
normalize_snapshot_paths(frames.join("\n\n"))
);

tui.set_owned_screen(/*owned*/ false)?;
Ok(())
}

#[tokio::test]
async fn footer_selection_defers_warning_clicks_and_preserves_the_draft() -> Result<()> {
let mut app = crate::app::test_support::make_test_app().await;
app.local_settings.tui.copy_on_select = CopyOnSelect::Never;
let mut tui = crate::tui::test_support::make_test_tui()?;
tui.set_owned_screen(/*owned*/ true)?;
let size = tui.terminal.size()?;
app.chat_widget
.apply_external_edit("draft stays here".into());
app.insert_history_cell(
&mut tui,
Box::new(history_cell::new_warning_event("Example warning".into())),
);
app.render_owned_transcript(&mut tui, size)?;
let draft = app.chat_widget.capture_thread_input_state();
let cursor = tui.terminal.last_known_cursor_pos;
let buffer = crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal);
let badge = buffer
.area
.positions()
.find(|position| buffer[*position].symbol() == "⚠")
.unwrap();
for event in [
mouse(Down(Left), badge.x, badge.y),
mouse(Drag(Left), badge.x + 11, badge.y),
mouse(Up(Left), badge.x + 11, badge.y),
] {
assert!(app.handle_rendered_selection_event(&mut tui, &event)?);
assert!(!app.chat_widget.keymap_contexts().is_warnings());
}
app.render_owned_transcript(&mut tui, size)?;
assert_eq!(
(
app.chat_widget.capture_thread_input_state(),
tui.terminal.last_known_cursor_pos
),
(draft, cursor)
);
{
let mut selection = app.chat_widget.rendered_selection.borrow_mut();
let crate::rendered_selection::RenderedSelection { view, cells, .. } = &mut *selection;
assert!(view.selected_text(cells).unwrap().contains("warning"));
}
insta::assert_snapshot!(
"fullscreen_footer_selection",
normalize_snapshot_paths(buffer_text(
crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal)
))
);
assert!(app.handle_rendered_selection_event(
&mut tui,
&TuiEvent::Key(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE))
)?);
// Dismissal consumes the first Escape, and a stationary click still opens the warning viewer.
for event in [
mouse(Down(Left), badge.x + 2, badge.y),
mouse(Up(Left), badge.x + 2, badge.y),
] {
assert!(app.handle_rendered_selection_event(&mut tui, &event)?);
}
assert!(app.chat_widget.keymap_contexts().is_warnings());
tui.set_owned_screen(/*owned*/ false)?;
Ok(())
}
6 changes: 6 additions & 0 deletions codex-rs/tui/src/app/right_click_paste.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ impl App {
let allowed = match source {
PasteSource::Clipboard => {
!self.transcript_view.has_selection_range()
&& !self
.chat_widget
.rendered_selection
.borrow()
.view
.has_selection_range()
&& self
.right_click_paste_environment
.allows(self.local_settings.tui.right_click_paste)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
source: tui/src/app/owned_transcript_tests.rs
assertion_line: 1545
expression: "normalize_snapshot_paths(buffer_text(crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal)))"
---


















Selecting footer · esc cancel

› draft stays here

GPT-5.6-Sol default · /tmp/project
⚠ 1 warning · f2 to view
14 changes: 13 additions & 1 deletion codex-rs/tui/src/bottom_pane/chat_composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@
//! Submission flushes expired characters and buffers before classifying Enter, independent of
//! UI flush ticks. `disable_paste_burst` bypasses detection; setting it flushes and clears in-flight state.
//! Mouse edits flush pending typing; selection and copy behavior lives in [`mouse`]. Confirmed
//! copies clear the selection while preserving the draft and cursor.
//! copies clear the selection while preserving the draft and cursor. Footer text uses a separate
//! read-only selection owner over its final rendered cells.
//!
//! See `codex-rs/tui/src/bottom_pane/paste_burst.rs` for the detailed state machine.
//!
Expand Down Expand Up @@ -752,6 +753,7 @@ impl ChatComposer {
external_editor_key: default_keymap
.primary_hint(KeymapContext::Global, "open_external_editor"),
warning_notice_area: std::cell::Cell::default(),
selection_revision: std::cell::Cell::default(),
show_warnings_key: default_keymap
.primary_hint(KeymapContext::Global, "open_warnings"),
show_transcript_key: default_keymap
Expand Down Expand Up @@ -4800,6 +4802,16 @@ impl ChatComposer {
if let Some((warning_area, line)) = warning_notice {
line.render(warning_area, buf);
}
if let Some(selection) = options.rendered_selection
&& !self.popup_active()
&& options.footer.is_none_or(|footer| !footer.is_interactive)
{
let revision = (options.warning_count, self.footer_props().is_task_running);
let changed = self.footer.selection_revision.replace(revision) != revision;
let mut selection = selection.borrow_mut();
selection.register(status.intersection(buf.area), changed);
selection.register(footer_rect.intersection(buf.area), changed);
}
let style = user_message_style();
Block::default().style(style).render(composer_rect, buf);
if !remote_images_rect.is_empty() {
Expand Down
Loading
Loading