diff --git a/codex-rs/tui/src/bottom_pane/textarea.rs b/codex-rs/tui/src/bottom_pane/textarea.rs index c45c86e5af..bf40bb6bd4 100644 --- a/codex-rs/tui/src/bottom_pane/textarea.rs +++ b/codex-rs/tui/src/bottom_pane/textarea.rs @@ -285,6 +285,11 @@ impl TextArea { code: KeyCode::Left, modifiers: KeyModifiers::NONE, .. + } + | KeyEvent { + code: KeyCode::Char('b'), + modifiers: KeyModifiers::CONTROL, + .. } => { self.move_cursor_left(); } @@ -292,6 +297,11 @@ impl TextArea { code: KeyCode::Right, modifiers: KeyModifiers::NONE, .. + } + | KeyEvent { + code: KeyCode::Char('f'), + modifiers: KeyModifiers::CONTROL, + .. } => { self.move_cursor_right(); } @@ -884,6 +894,34 @@ mod tests { assert_eq!(t.cursor(), 3); } + #[test] + fn ctrl_f_and_ctrl_b_move_one_char() { + use crossterm::event::KeyCode; + use crossterm::event::KeyEvent; + use crossterm::event::KeyModifiers; + + let mut t = ta_with("abc"); + // Forward moves + t.set_cursor(0); + t.input(KeyEvent::new(KeyCode::Char('f'), KeyModifiers::CONTROL)); + assert_eq!(t.cursor(), 1); + t.input(KeyEvent::new(KeyCode::Char('f'), KeyModifiers::CONTROL)); + assert_eq!(t.cursor(), 2); + t.input(KeyEvent::new(KeyCode::Char('f'), KeyModifiers::CONTROL)); + assert_eq!(t.cursor(), 3); + + // Backward moves + t.input(KeyEvent::new(KeyCode::Char('b'), KeyModifiers::CONTROL)); + assert_eq!(t.cursor(), 2); + t.input(KeyEvent::new(KeyCode::Char('b'), KeyModifiers::CONTROL)); + assert_eq!(t.cursor(), 1); + t.input(KeyEvent::new(KeyCode::Char('b'), KeyModifiers::CONTROL)); + assert_eq!(t.cursor(), 0); + // Further backward at start stays at 0 + t.input(KeyEvent::new(KeyCode::Char('b'), KeyModifiers::CONTROL)); + assert_eq!(t.cursor(), 0); + } + #[test] fn cursor_left_and_right_handle_graphemes() { let mut t = ta_with("a👍b");