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
5 changes: 5 additions & 0 deletions codex-rs/config/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,11 @@ pub struct Tui {
#[serde(default)]
pub copy_on_select: CopyOnSelect,

/// Deselect transcript text after Copy on select confirms clipboard delivery.
/// Defaults to `false` and has no effect when Copy on select is off.
#[serde(default)]
pub copy_on_select_clear_selection: bool,

/// Right-click text paste fallback. Defaults to `auto` (Windows/WSL/Linux).
/// `on` also enables macOS; neither mode reads over SSH or in recognized VS Code terminals.
/// This controls the fullscreen fallback, not the terminal's own paste binding.
Expand Down
5 changes: 5 additions & 0 deletions codex-rs/core/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4648,6 +4648,11 @@
"default": "auto",
"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."
},
"copy_on_select_clear_selection": {
"default": false,
"description": "Deselect transcript text after Copy on select confirms clipboard delivery. Defaults to `false` and has no effect when Copy on select is off.",
"type": "boolean"
},
"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`.",
"type": "boolean"
Expand Down
2 changes: 2 additions & 0 deletions codex-rs/core/src/config/config_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,7 @@ fn config_toml_deserializes_model_availability_nux() {
fullscreen_transcript: true,
mouse_scroll_speed: None,
copy_on_select: Default::default(),
copy_on_select_clear_selection: false,
right_click_paste: Default::default(),
alternate_screen: AltScreenMode::default(),
status_line: None,
Expand Down Expand Up @@ -4417,6 +4418,7 @@ fn tui_config_missing_notifications_field_defaults_to_enabled() {
fullscreen_transcript: true,
mouse_scroll_speed: None,
copy_on_select: Default::default(),
copy_on_select_clear_selection: false,
right_click_paste: Default::default(),
alternate_screen: AltScreenMode::Auto,
status_line: None,
Expand Down
18 changes: 18 additions & 0 deletions codex-rs/core/src/config/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ pub enum ConfigEdit {
SetSkillConfig { path: PathBuf, enabled: bool },
/// Set or clear a skill config entry under `[[skills.config]]` by name.
SetSkillConfigByName { name: String, enabled: bool },
/// Enable or disable TUI notifications without replacing custom event filters.
SetTuiNotificationsEnabled { enabled: bool },
/// Set trust_level under `[projects."<path>"]`,
/// migrating inline tables to explicit tables.
SetProjectTrustLevel { path: PathBuf, level: TrustLevel },
Expand Down Expand Up @@ -311,6 +313,22 @@ impl ConfigDocument {
ConfigEdit::SetSkillConfigByName { name, enabled } => {
Ok(self.set_skill_config(SkillConfigSelector::Name(name.clone()), *enabled))
}
ConfigEdit::SetTuiNotificationsEnabled { enabled } => {
let segments = ["tui", "notifications"];
let custom_filters = segments
.iter()
.try_fold(self.doc.as_item(), |item, segment| {
item.as_table_like()?.get(segment)
})
.and_then(TomlItem::as_array)
.is_some();
if custom_filters {
anyhow::bail!(
"Event-specific notifications are configured. Edit those filters in the config file."
);
}
Ok(self.write_value(&segments, value(*enabled)))
}
ConfigEdit::SetPath { segments, value } => {
if is_structured_feature_path(segments) && value.as_bool().is_some() {
let mut existing = Some(self.doc.as_item());
Expand Down
36 changes: 22 additions & 14 deletions codex-rs/core/src/config/edit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,28 +1495,36 @@ fn blocking_clear_path_noop_when_missing() {
}

#[test]
fn blocking_set_path_updates_notifications() {
fn blocking_notification_toggle_updates_boolean_and_preserves_custom_filters() {
let tmp = tempdir().expect("tmpdir");
let codex_home = tmp.path();
let config_path = codex_home.join(CONFIG_TOML_FILE);

let item = value(false);
apply_blocking(
codex_home,
&[ConfigEdit::SetPath {
segments: vec!["tui".to_string(), "notifications".to_string()],
value: item,
}],
&[ConfigEdit::SetTuiNotificationsEnabled { enabled: false }],
)
.expect("apply");
assert_eq!(
std::fs::read_to_string(&config_path).expect("read config"),
"[tui]\nnotifications = false\n"
);

let raw = std::fs::read_to_string(codex_home.join(CONFIG_TOML_FILE)).expect("read config");
let config: TomlValue = toml::from_str(&raw).expect("parse config");
let notifications = config
.get("tui")
.and_then(|item| item.as_table())
.and_then(|tbl| tbl.get("notifications"))
.and_then(toml::Value::as_bool);
assert_eq!(notifications, Some(false));
let custom_filters = "[tui]\nnotifications = [\"approval-requested\"]\n";
std::fs::write(&config_path, custom_filters).expect("write config");
let error = apply_blocking(
codex_home,
&[ConfigEdit::SetTuiNotificationsEnabled { enabled: false }],
)
.expect_err("custom filters should reject a boolean toggle");
assert_eq!(
error.to_string(),
"Event-specific notifications are configured. Edit those filters in the config file."
);
assert_eq!(
std::fs::read_to_string(config_path).expect("read config"),
custom_filters
);
}

#[tokio::test]
Expand Down
7 changes: 7 additions & 0 deletions codex-rs/core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,9 @@ pub struct Config {
/// Override the terminal-specific default for copying transcript mouse selections.
pub tui_copy_on_select: codex_config::types::CopyOnSelect,

/// Whether to deselect transcript text after a confirmed automatic copy.
pub tui_copy_on_select_clear_selection: bool,

/// Right-click text paste fallback for the fullscreen TUI.
pub tui_right_click_paste: codex_config::types::RightClickPaste,

Expand Down Expand Up @@ -4597,6 +4600,10 @@ impl Config {
.as_ref()
.map(|tui| tui.copy_on_select)
.unwrap_or_default(),
tui_copy_on_select_clear_selection: cfg
.tui
.as_ref()
.is_some_and(|tui| tui.copy_on_select_clear_selection),
tui_right_click_paste: cfg
.tui
.as_ref()
Expand Down
1 change: 1 addition & 0 deletions codex-rs/thread-manager-sample/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ async fn new_config(
tui_fullscreen_transcript: false,
tui_mouse_scroll_speed: None,
tui_copy_on_select: Default::default(),
tui_copy_on_select_clear_selection: false,
tui_right_click_paste: Default::default(),
tui_alternate_screen: AltScreenMode::Auto,
tui_status_line: None,
Expand Down
71 changes: 71 additions & 0 deletions codex-rs/tui/src/activation_key_guard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//! Suppress a key held across a view transition from activating the child view.
//!
//! Terminals with enhanced keyboard reporting distinguish a held `Repeat` from a fresh `Press`.
//! Press-only terminals use a bounded window that extends while repeat events continue to arrive.

use crate::key_hint::KeyBinding;
use crossterm::event::KeyEventKind;
use std::time::Duration;
use std::time::Instant;

const INITIAL_GUARD: Duration = Duration::from_secs(/*secs*/ 1);
const LEGACY_REPEAT_GUARD: Duration = Duration::from_secs(/*secs*/ 1);

#[derive(Clone, Copy)]
pub(crate) struct ActivationKeyGuard {
key: KeyBinding,
block_until: Instant,
key_releases_reported: bool,
active: bool,
}

impl ActivationKeyGuard {
pub(crate) fn new_at(key: KeyBinding, now: Instant, key_releases_reported: bool) -> Self {
Self {
key,
block_until: now.checked_add(INITIAL_GUARD).unwrap_or(now),
key_releases_reported,
active: true,
}
}

pub(crate) fn consume(&mut self, key: KeyBinding, kind: KeyEventKind) -> bool {
self.consume_at(key, kind, Instant::now())
}

fn consume_at(&mut self, key: KeyBinding, kind: KeyEventKind, now: Instant) -> bool {
if !self.active {
return false;
}

if self.key.is_same_physical_key(key) {
if kind == KeyEventKind::Release {
self.active = false;
return true;
}
// Enhanced keyboard reporting labels a held key as Repeat, so a new Press is fresh.
if self.key_releases_reported && kind == KeyEventKind::Press {
self.active = false;
return false;
}
if kind == KeyEventKind::Repeat || now <= self.block_until {
let repeat_until = now.checked_add(LEGACY_REPEAT_GUARD).unwrap_or(now);
self.block_until = self.block_until.max(repeat_until);
return true;
}
self.active = false;
} else if matches!(kind, KeyEventKind::Press | KeyEventKind::Repeat) {
self.active = false;
}

false
}

pub(crate) fn is_active(self) -> bool {
self.active
}
}

#[cfg(test)]
#[path = "activation_key_guard_tests.rs"]
mod tests;
39 changes: 39 additions & 0 deletions codex-rs/tui/src/activation_key_guard_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use super::*;
use crate::key_hint;
use crossterm::event::KeyCode;

#[test]
fn suppresses_activation_until_release_and_bounds_legacy_presses() {
let start = Instant::now();
let key = key_hint::plain(KeyCode::Enter);
let mut guard = ActivationKeyGuard::new_at(key, start, /*key_releases_reported*/ true);

assert!(guard.consume_at(key, KeyEventKind::Repeat, start));
assert!(guard.consume_at(key, KeyEventKind::Release, start));
assert!(!guard.consume_at(key, KeyEventKind::Press, start));

let mut guard = ActivationKeyGuard::new_at(key, start, /*key_releases_reported*/ false);
for elapsed in [900, 1_300] {
assert!(guard.consume_at(
key,
KeyEventKind::Press,
start + Duration::from_millis(/*millis*/ elapsed),
));
}
assert!(!guard.consume_at(
key,
KeyEventKind::Press,
start + Duration::from_millis(/*millis*/ 2_301),
));
assert!(!guard.is_active());

let mut guard = ActivationKeyGuard::new_at(
key_hint::plain(KeyCode::BackTab),
start,
/*key_releases_reported*/ true,
);
let tab = key_hint::plain(KeyCode::Tab);
assert!(guard.consume_at(tab, KeyEventKind::Repeat, start));
assert!(guard.consume_at(tab, KeyEventKind::Release, start));
assert!(!guard.is_active());
}
48 changes: 39 additions & 9 deletions codex-rs/tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ use crate::history_cell::HistoryCell;
#[cfg(not(debug_assertions))]
use crate::history_cell::UpdateAvailableHistoryCell;
use crate::hooks_rpc::HookTrustUpdate;
use crate::key_hint::KeyBinding;
use crate::key_hint::KeyBindingListExt;
use crate::keymap::KeyChordMatcher;
use crate::keymap::RuntimeKeymap;
Expand Down Expand Up @@ -216,6 +217,7 @@ mod app_server_thread_ownership;
mod backend_banner_fallback;
mod background_requests;
mod composer_hints;
mod config_panel;
mod config_persistence;
mod connector_mentions;
mod daemon_menu;
Expand Down Expand Up @@ -256,6 +258,7 @@ mod replay_filter;
mod resize_reflow;
mod resume_config;
mod right_click_paste;
pub(crate) use right_click_paste::PasteEnvironment;
mod safety_buffering;
mod server_version_notice;
mod session_lifecycle;
Expand Down Expand Up @@ -529,6 +532,8 @@ struct InitialHistoryReplayBuffer {

pub(crate) struct App {
feature_write_lock: Arc<tokio::sync::Mutex<()>>,
config_notification_test_generation: u64,
config_notification_test_pending: Option<u64>,
model_catalog: Arc<ModelCatalog>,
pub(crate) session_telemetry: SessionTelemetry,
pub(crate) app_event_tx: AppEventSender,
Expand Down Expand Up @@ -574,6 +579,7 @@ pub(crate) struct App {
pub(crate) enhanced_keys_supported: bool,
pub(crate) keymap: RuntimeKeymap,
pub(crate) key_chord_matcher: KeyChordMatcher,
routed_key_activation: Option<KeyBinding>,

/// The foreground loop owns stream pacing; stopped animations have no timer.
pub(crate) commit_animation: Option<tokio::time::Interval>,
Expand Down Expand Up @@ -899,6 +905,9 @@ impl App {
if self.reconnect.offline
&& !transcript_owns_input
&& !self.chat_widget.keymap_contexts().is_warnings()
&& !self
.chat_widget
.active_view_accepts_input_when_disconnected()
&& let TuiEvent::Key(key) = &event
&& matches!(key.kind, KeyEventKind::Press | KeyEventKind::Repeat)
&& key.modifiers.contains(KeyModifiers::CONTROL)
Expand All @@ -924,6 +933,11 @@ impl App {
{
self.cancel_pending_key_chord();
}
if matches!(&event, TuiEvent::FocusLost)
|| matches!(&event, TuiEvent::Mouse(mouse) if mouse.kind != crossterm::event::MouseEventKind::Moved)
{
self.chat_widget.interrupt_config_editor_transition();
}

if self.overlay.is_none()
&& self
Expand Down Expand Up @@ -1032,16 +1046,29 @@ impl App {
&& self.chat_widget.agents_navigation_key_available()))
{
self.open_agents_overview(app_server);
} else if self.reconnect.presentation == reconnect::ReconnectPresentation::Overview {
self.chat_widget.handle_disconnected_view_key(*key);
if self
.chat_widget
.selected_index_for_present_view(agents_overview::AGENTS_OVERVIEW_VIEW_ID)
.is_none()
} else if self
.chat_widget
.active_view_accepts_input_when_disconnected()
|| (self.reconnect.presentation == reconnect::ReconnectPresentation::Overview
&& self
.chat_widget
.active_view_is(agents_overview::AGENTS_OVERVIEW_VIEW_ID))
{
let activation_key = self.routed_key_activation.take();
self.chat_widget
.handle_disconnected_view_key(*key, activation_key);
if self.reconnect.presentation == reconnect::ReconnectPresentation::Overview
&& self
.chat_widget
.selected_index_for_present_view(agents_overview::AGENTS_OVERVIEW_VIEW_ID)
.is_none()
{
self.reconnect.presentation = reconnect::ReconnectPresentation::Conversation;
}
} else {
if self.reconnect.presentation == reconnect::ReconnectPresentation::Overview {
self.reconnect.presentation = reconnect::ReconnectPresentation::Conversation;
}
self.chat_widget
.handle_restricted_key(*key, RestrictedInputMode::Disconnected);
}
Expand Down Expand Up @@ -1090,12 +1117,15 @@ impl App {
self.reset_backtrack_state();
}
}
self.chat_widget.handle_paste(pasted);
if self.reconnect.offline
let restrict_disconnected_input = self.reconnect.offline
&& !self.chat_widget.keymap_contexts().is_warnings()
&& self.reconnect.presentation
== reconnect::ReconnectPresentation::Conversation
{
&& !self
.chat_widget
.active_view_accepts_input_when_disconnected();
self.chat_widget.handle_paste(pasted);
if restrict_disconnected_input {
self.chat_widget.handle_restricted_key(
KeyEvent::new(KeyCode::Null, KeyModifiers::NONE),
RestrictedInputMode::Disconnected,
Expand Down
Loading
Loading