From b420c7ca54e1caa01ebbba608b95495aaa304f69 Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Wed, 25 Nov 2026 18:04:48 +0000 Subject: [PATCH] Preserve sidebar clicks when the terminal gains focus (#63999) ## Why A terminal can report a focus gain between mouse-down and mouse-up. Clearing the pending sidebar press on that event causes the release to be ignored, so clicking the tab chooser's close button can fail to open the confirmation dialog. ## What changed Keep the pending sidebar press on `TuiEvent::FocusGained` so the mouse release can complete the click. ## Testing Extend the tab chooser test to send a focus gain between the press and release and check that the close confirmation dialog appears. GitOrigin-RevId: 4173292c50383304e9ef62104251434be7580789 --- codex-rs/tui/src/app.rs | 2 ++ codex-rs/tui/src/app/tests.rs | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/codex-rs/tui/src/app.rs b/codex-rs/tui/src/app.rs index 00007ed5b2..ef363d9dbb 100644 --- a/codex-rs/tui/src/app.rs +++ b/codex-rs/tui/src/app.rs @@ -903,7 +903,9 @@ impl App { self.chat_widget.rendered_selection.borrow_mut().end_drag(); } match &event { + // A terminal can report focus between mouse-down and mouse-up. TuiEvent::Draw + | TuiEvent::FocusGained | TuiEvent::Mouse(crossterm::event::MouseEvent { kind: MouseEventKind::Up(_) | MouseEventKind::Moved, .. diff --git a/codex-rs/tui/src/app/tests.rs b/codex-rs/tui/src/app/tests.rs index 875f88512b..b5b3a269c0 100644 --- a/codex-rs/tui/src/app/tests.rs +++ b/codex-rs/tui/src/app/tests.rs @@ -5660,13 +5660,13 @@ async fn handle_start_side_seeds_navigation_before_thread_started() -> Result<() let buffer = tui.terminal.previous_buffer(); let style = |x| buffer[(x, chooser.y)].style(); assert_eq!([close_x - 1, close_x + 1].map(style), [style(close_x); 2]); - for kind in [down, release] { - boxed_future!(app.handle_tui_event( - &mut tui, - &mut app_server, - mouse(kind, close_x + 1, chooser.y) - )) - .await?; + // Rex reports focus again between the press and release of a single click. + for event in [ + mouse(down, close_x + 1, chooser.y), + TuiEvent::FocusGained, + mouse(release, close_x + 1, chooser.y), + ] { + boxed_future!(app.handle_tui_event(&mut tui, &mut app_server, event)).await?; } let frame = side_frame(&mut app, &mut tui, even)?; let dialog = frame