From 702238f0043b3bbc95bd97ba5131eea6e1160e5a Mon Sep 17 00:00:00 2001 From: Akrelion45 Date: Mon, 17 Nov 2025 04:15:06 +0100 Subject: [PATCH] Fix AltGr/backslash input on Windows Codex terminal (#6720) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Summary - Treat AltGr chords (Ctrl+Alt) as literal character input in the Codex TUI textarea so Windows terminals that report backslash and other characters via AltGr insert correctly. - Add regression test altgr_ctrl_alt_char_inserts_literal to ensure Ctrl+Alt char events append the character and advance the cursor. ### Motivation On US/UK keyboard layouts, backslash is produced by a plain key, so Ctrl+Alt handling is never exercised and the bug isn’t visible. On many non‑US layouts (e.g., German), backslash and other symbols require AltGr, which terminals report as Ctrl+Alt+. Our textarea previously filtered these chords like navigation bindings, so AltGr input was dropped on affected layouts. This change treats AltGr chords as literal input so backslash and similar symbols work on Windows terminals. This fixes multiple reported Issues where the \ symbol got cut off. Like: C:\Users\Admin became C:UsersAdmin Co-authored-by: Eric Traut --- codex-rs/tui/src/bottom_pane/textarea.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/codex-rs/tui/src/bottom_pane/textarea.rs b/codex-rs/tui/src/bottom_pane/textarea.rs index cd913b00d..0a7faa4fc 100644 --- a/codex-rs/tui/src/bottom_pane/textarea.rs +++ b/codex-rs/tui/src/bottom_pane/textarea.rs @@ -247,6 +247,16 @@ impl TextArea { } if modifiers == (KeyModifiers::CONTROL | KeyModifiers::ALT) => { self.delete_backward_word() }, + KeyEvent { + code: KeyCode::Char(c), + modifiers, + .. + } if modifiers.contains(KeyModifiers::ALT) + && modifiers.contains(KeyModifiers::CONTROL) => + { + // AltGr on many keyboards reports as Ctrl+Alt; treat it as a literal char. + self.insert_str(&c.to_string()); + }, KeyEvent { code: KeyCode::Backspace, modifiers: KeyModifiers::ALT, @@ -1454,6 +1464,17 @@ mod tests { assert_eq!(t.cursor(), 3); } + #[test] + fn altgr_ctrl_alt_char_inserts_literal() { + let mut t = ta_with(""); + t.input(KeyEvent::new( + KeyCode::Char('c'), + KeyModifiers::CONTROL | KeyModifiers::ALT, + )); + assert_eq!(t.text(), "c"); + assert_eq!(t.cursor(), 1); + } + #[test] fn cursor_vertical_movement_across_lines_and_bounds() { let mut t = ta_with("short\nloooooooooong\nmid");