From 16f11a89d8c08105f54fa35b3915e9543b9a728f Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Wed, 20 Aug 2025 01:34:52 +0900 Subject: [PATCH] Fix #2429 Tweak the cursor position after tab completion (#2442) This pull request resolves #2429; I was also feeling that this is not great dev experience, so we should fix. --- codex-rs/tui/src/bottom_pane/chat_composer.rs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/codex-rs/tui/src/bottom_pane/chat_composer.rs b/codex-rs/tui/src/bottom_pane/chat_composer.rs index 71483f04..5d555aa0 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer.rs @@ -273,6 +273,7 @@ impl ChatComposer { if !starts_with_cmd { self.textarea.set_text(&format!("/{} ", cmd.command())); + self.textarea.set_cursor(self.textarea.text().len()); } } (InputResult::None, true) @@ -1071,6 +1072,28 @@ mod tests { } } + #[test] + fn slash_tab_completion_moves_cursor_to_end() { + use crossterm::event::KeyCode; + use crossterm::event::KeyEvent; + use crossterm::event::KeyModifiers; + + let (tx, _rx) = std::sync::mpsc::channel(); + let sender = AppEventSender::new(tx); + let mut composer = + ChatComposer::new(true, sender, false, "Ask Codex to do anything".to_string()); + + for ch in ['/', 'c'] { + let _ = composer.handle_key_event(KeyEvent::new(KeyCode::Char(ch), KeyModifiers::NONE)); + } + + let (_result, _needs_redraw) = + composer.handle_key_event(KeyEvent::new(KeyCode::Tab, KeyModifiers::NONE)); + + assert_eq!(composer.textarea.text(), "/compact "); + assert_eq!(composer.textarea.cursor(), composer.textarea.text().len()); + } + #[test] fn slash_mention_dispatches_command_and_inserts_at() { use crossterm::event::KeyCode;