Skip to content

Windows Terminal: fullscreen TUI intercepts right-click paste without a paste fallback #47469

Closed

Description

@JunWang-Lin

Summary

After upgrading to Codex CLI 0.156.0 and enabling Fullscreen mode through /tui, normal right-click no longer pastes clipboard text into the composer. Switching back to Scrollback mode restores right-click paste.

Shift + right-click does work in Fullscreen mode. The issue is the loss of the terminal's normal right-click paste behavior without an obvious hint about the alternative gesture.

Environment

  • Codex CLI: 0.156.0 (npm installation, native Windows)
  • OS: Windows 11 Pro, build 26200
  • Terminal: Windows Terminal 1.24.11911.0
  • Configuration: [tui] with fullscreen_transcript = true
  • Windows Terminal: copyOnSelect = true

Steps to reproduce

  1. Start Codex CLI, choose Fullscreen using /tui, and restart Codex to apply it.
  2. Copy some plain text to the clipboard.
  3. With no text selected in the composer or transcript, right-click inside the composer.
  4. Observe that no text is pasted.
  5. Press Shift + right-click: the clipboard text is pasted.
  6. Switch to Scrollback mode and restart Codex. Normal right-click pastes again.

Expected behavior

Ideally, right-click in the composer with no active selection should paste, while preserving right-click copying when a selection exists.

If copy-only right-click is intentional in Fullscreen mode, please make the change discoverable, for example by documenting Shift + right-click in the /tui picker or relevant shortcut help.

Actual behavior

Normal right-click with no selection has no visible effect in Fullscreen mode. The same terminal supports normal right-click paste in Scrollback mode.

Source-level observations

The following appears to explain the behavior:

  • Fullscreen screen ownership enables mouse capture in tui.rs.
  • The Windows implementation explicitly uses EnableMouseCapture.execute_winapi() in alternate_screen.rs.
  • Composer right-click is recognized as a copy request, but mouse_selection_range()? returns None when there is no selection. There is no clipboard-paste fallback in chat_composer/mouse.rs.
  • Unhandled mouse events ultimately reach a no-op branch in app.rs.

Related change: #46895 introduced right-click copying for transcript and composer selections.

Verification scope and workaround

The interactive behavior above was reproduced on 0.156.0. Source inspection found the relevant behavior unchanged in 0.156.1 and in main inspected on 2026-09-23; those versions were not interactively tested.

Confirmed workaround: Shift + right-click, or switching back to Scrollback mode.

Activity

  1. added
    bug
    CLI
    windows-os
    TUI
    on Sep 23, 2026
  2. fidonan commented on Sep 26, 2026

    @fidonan

    Also affected on Codex CLI 0.157.1, installed via npm on native Windows x64 with Windows Terminal and PowerShell. In this case, right-click copying works, but a plain right-click with no selection does not paste text. Windows Terminal has copyOnSelect = false, so this is not limited to the copyOnSelect = true configuration in the original report.

    Reproduction

    1. Start the fullscreen Codex TUI on Windows.
    2. Copy ordinary text, for example two lines containing both ASCII and Chinese characters.
    3. Ensure there is no active selection and right-click in the composer.
    4. No text is inserted. Right-click copying of an existing selection still works.

    Expected: a right-click with no selection inserts clipboard text into the draft without submitting it; right-click copying keeps its existing behavior.

    Source analysis and proposed local fix

    Inspected and patched rust-v0.157.1, commit 36650394c5b38c2990ccf2a3457165ca3e9d9726:

    The proposed Windows-only fallback runs after the existing selection-copy handlers decline the event. An unmodified right-button press reads text using the existing arboard dependency and converts it into TuiEvent::Paste. It then uses the existing paste routing and newline normalization. Mouse release and modified clicks do not trigger clipboard reads; overlays and active modal views are left to their existing handlers.

    This addresses native Windows text pasting. It is not presented as a fix for remote-host clipboard access or Linux/macOS mouse-paste behavior.

    Validation

    A local build of codex-cli succeeded. These focused tests passed 8/8:

    just test -p codex-tui --lib --locked -E 'test(mouse_paste) | test(fullscreen_composer_mouse_copy_and_input_ownership) | test(right_click_copy)'
    

    Four new tests cover:

    • Right-button press becomes a paste event; release does not read again.
    • Other mouse gestures do not read the clipboard.
    • Empty/unavailable clipboard leaves the draft intact.
    • Chinese/multiline text follows normal newline normalization and stays in the composer without submitting.

    Four existing composer/transcript right-click-copy regression tests also passed. The new tests use injected clipboard text, not the real system clipboard. The rest of the TUI suite was not run.

    Manual verification update (2026-09-26): After installation, the affected user tested the local fix and confirmed that right-click text paste is working again in Windows Terminal. This adds user-confirmed interactive verification to the automated results above. This patch has not been rebased onto or tested against current main.

    Proposed patch

    The patch below contains only the three TUI source/test files for this issue. No terminal settings or additional dependencies are required.

    Patch against rust-v0.157.1 (3 files, 148 added lines)
    diff --git a/codex-rs/tui/src/app.rs b/codex-rs/tui/src/app.rs
    index 9349649..b672526 100644
    --- a/codex-rs/tui/src/app.rs
    +++ b/codex-rs/tui/src/app.rs
    @@ -231,6 +231,8 @@ mod loaded_threads;
     mod managed_worktree_creation;
     mod misalignment_policy;
     mod model_defaults;
    +#[cfg(windows)]
    +mod mouse_paste;
     mod new_session;
     pub(crate) use new_session::has_launch_setting;
     mod native_history;
    @@ -960,6 +962,20 @@ impl App {
             {
                 return Ok(AppRunControl::Continue);
             }
    +        // Mouse capture prevents Windows Terminal from pasting on a plain right click.
    +        // Give selection-copy handlers priority, then route clipboard text as a normal paste.
    +        #[cfg(windows)]
    +        if self.paste_unhandled_mouse(&mut event, || {
    +            arboard::Clipboard::new()
    +                .and_then(|mut clipboard| clipboard.get_text())
    +                .map_err(|error| error.to_string())
    +        }) {
    +            self.cancel_pending_key_chord();
    +            self.cancel_primed_browsing_for_event(&event);
    +            if self.handle_owned_transcript_event(tui, app_server, &event)? {
    +                return Ok(AppRunControl::Continue);
    +            }
    +        }
             // Leave browsing before unhandled editing input reaches shortcuts or offline input.
             // Offline Enter cannot confirm a rewind and leaves the preview available to read.
             if tui.is_owned_screen()
    diff --git a/codex-rs/tui/src/app/mouse_paste.rs b/codex-rs/tui/src/app/mouse_paste.rs
    new file mode 100644
    index 0000000..0a522f8
    --- /dev/null
    +++ b/codex-rs/tui/src/app/mouse_paste.rs
    @@ -0,0 +1,45 @@
    +//! Native Windows right-click text paste after selection-copy handlers decline the event.
    +//! Reuse the normal paste event so line endings, input restrictions, and submission behavior
    +//! remain the same as a terminal-provided paste. Clipboard reads only follow an explicit click.
    +
    +use super::App;
    +use crate::tui::TuiEvent;
    +use crossterm::event::MouseButton;
    +use crossterm::event::MouseEventKind;
    +
    +impl App {
    +    pub(super) fn paste_unhandled_mouse(
    +        &mut self,
    +        event: &mut TuiEvent,
    +        read_text: impl FnOnce() -> Result<String, String>,
    +    ) -> bool {
    +        if !matches!(event, TuiEvent::Mouse(mouse)
    +            if mouse.kind == MouseEventKind::Down(MouseButton::Right)
    +                && mouse.modifiers.is_empty())
    +            || self.overlay.is_some()
    +            || self.chat_widget.has_active_view()
    +            || self
    +                .transcript_view
    +                .selected_text(&self.transcript_cells)
    +                .is_some_and(|text| !text.is_empty())
    +        {
    +            return false;
    +        }
    +        match read_text() {
    +            Ok(text) if !text.is_empty() => {
    +                *event = TuiEvent::Paste(text);
    +                true
    +            }
    +            Ok(_) => false,
    +            Err(error) => {
    +                self.chat_widget
    +                    .add_error_message(format!("Could not paste clipboard text: {error}"));
    +                false
    +            }
    +        }
    +    }
    +}
    +
    +#[cfg(test)]
    +#[path = "mouse_paste_tests.rs"]
    +mod tests;
    diff --git a/codex-rs/tui/src/app/mouse_paste_tests.rs b/codex-rs/tui/src/app/mouse_paste_tests.rs
    new file mode 100644
    index 0000000..2e1d5b3
    --- /dev/null
    +++ b/codex-rs/tui/src/app/mouse_paste_tests.rs
    @@ -0,0 +1,87 @@
    +use crate::app::test_support::make_test_app;
    +use crate::tui::TuiEvent;
    +use crossterm::event::KeyModifiers;
    +use crossterm::event::MouseButton;
    +use crossterm::event::MouseEvent;
    +use crossterm::event::MouseEventKind;
    +use pretty_assertions::assert_eq;
    +
    +fn mouse(kind: MouseEventKind, modifiers: KeyModifiers) -> TuiEvent {
    +    TuiEvent::Mouse(MouseEvent {
    +        kind,
    +        column: 4,
    +        row: 4,
    +        modifiers,
    +    })
    +}
    +
    +#[tokio::test]
    +async fn right_click_becomes_one_paste_and_release_does_not_read_again() {
    +    let mut app = make_test_app().await;
    +    let mut event = mouse(MouseEventKind::Down(MouseButton::Right), KeyModifiers::NONE);
    +    assert!(app.paste_unhandled_mouse(&mut event, || Ok("hello\r\n世界".into())));
    +    let TuiEvent::Paste(text) = event else {
    +        panic!("right click must route through the normal paste event");
    +    };
    +    assert_eq!(text, "hello\r\n世界");
    +    let mut release = mouse(MouseEventKind::Up(MouseButton::Right), KeyModifiers::NONE);
    +    assert!(!app.paste_unhandled_mouse(&mut release, || panic!("duplicate clipboard read")));
    +}
    +
    +#[tokio::test]
    +async fn other_mouse_gestures_do_not_read_the_clipboard() {
    +    let mut app = make_test_app().await;
    +    for (kind, modifiers) in [
    +        (MouseEventKind::Down(MouseButton::Left), KeyModifiers::NONE),
    +        (MouseEventKind::ScrollUp, KeyModifiers::NONE),
    +        (
    +            MouseEventKind::Down(MouseButton::Right),
    +            KeyModifiers::SHIFT,
    +        ),
    +        (
    +            MouseEventKind::Down(MouseButton::Right),
    +            KeyModifiers::CONTROL,
    +        ),
    +    ] {
    +        assert!(!app.paste_unhandled_mouse(&mut mouse(kind, modifiers), || {
    +            panic!("unrelated gesture must not read the clipboard")
    +        }));
    +    }
    +}
    +
    +#[tokio::test]
    +async fn empty_or_unavailable_clipboard_preserves_the_draft() {
    +    let mut app = make_test_app().await;
    +    app.chat_widget
    +        .apply_external_edit("keep this draft".into());
    +    let before = app.chat_widget.capture_thread_input_state();
    +    for contents in [Ok(String::new()), Err("clipboard busy".into())] {
    +        let mut event = mouse(MouseEventKind::Down(MouseButton::Right), KeyModifiers::NONE);
    +        assert!(!app.paste_unhandled_mouse(&mut event, || contents));
    +        assert!(matches!(event, TuiEvent::Mouse(_)));
    +        assert_eq!(app.chat_widget.capture_thread_input_state(), before);
    +    }
    +}
    +
    +#[tokio::test]
    +async fn right_click_paste_normalizes_newlines_without_submitting() -> color_eyre::eyre::Result<()> {
    +    let mut app = make_test_app().await;
    +    let mut server = Box::pin(crate::start_embedded_app_server_for_picker(&app.config))
    +        .await
    +        .expect("start test app server");
    +    let mut tui = crate::tui::test_support::make_test_tui()?;
    +    tui.set_owned_screen(/*owned*/ true)?;
    +    app.chat_widget.apply_external_edit("draft: ".into());
    +    let size = tui.terminal.size()?;
    +    app.render_owned_transcript(&mut tui, size)?;
    +    let mut event = mouse(MouseEventKind::Down(MouseButton::Right), KeyModifiers::NONE);
    +    assert!(app.paste_unhandled_mouse(&mut event, || Ok("hello\r\n世界\rnext".into())));
    +    app.handle_tui_event(&mut tui, &mut server, event).await?;
    +    assert_eq!(
    +        app.chat_widget.composer_text_with_pending(),
    +        "draft: hello\n世界\nnext"
    +    );
    +    tui.set_owned_screen(/*owned*/ false)?;
    +    server.shutdown().await?;
    +    Ok(())
    +}
  3. bc-openai commented on Oct 1, 2026

    @bc-openai
    Contributor

    Thanks for the report! This is fixed in 0.158.0.

  4. wbdb commented on Oct 3, 2026

    @wbdb

    @bc-openai The problem persists in version 0.160.0 via PuTTY/SSH connection to Debian / Pi4:

    Image
  5. wbdb commented on Oct 31, 2026

    @wbdb

    @bc-openai same for 0.166.0. Edit: Worked when I change PuTTY settings to:

    „Disable xterm-style mouse reporting“

    Image

    But then you have the familiar drawbacks, such as scrolling through the Codex history, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLITUIbugwindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions