Skip to content

Commit 16f11a8

Browse files
authored
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.
1 parent e7e5fe9 commit 16f11a8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

codex-rs/tui/src/bottom_pane/chat_composer.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ impl ChatComposer {
273273

274274
if !starts_with_cmd {
275275
self.textarea.set_text(&format!("/{} ", cmd.command()));
276+
self.textarea.set_cursor(self.textarea.text().len());
276277
}
277278
}
278279
(InputResult::None, true)
@@ -1071,6 +1072,28 @@ mod tests {
10711072
}
10721073
}
10731074

1075+
#[test]
1076+
fn slash_tab_completion_moves_cursor_to_end() {
1077+
use crossterm::event::KeyCode;
1078+
use crossterm::event::KeyEvent;
1079+
use crossterm::event::KeyModifiers;
1080+
1081+
let (tx, _rx) = std::sync::mpsc::channel();
1082+
let sender = AppEventSender::new(tx);
1083+
let mut composer =
1084+
ChatComposer::new(true, sender, false, "Ask Codex to do anything".to_string());
1085+
1086+
for ch in ['/', 'c'] {
1087+
let _ = composer.handle_key_event(KeyEvent::new(KeyCode::Char(ch), KeyModifiers::NONE));
1088+
}
1089+
1090+
let (_result, _needs_redraw) =
1091+
composer.handle_key_event(KeyEvent::new(KeyCode::Tab, KeyModifiers::NONE));
1092+
1093+
assert_eq!(composer.textarea.text(), "/compact ");
1094+
assert_eq!(composer.textarea.cursor(), composer.textarea.text().len());
1095+
}
1096+
10741097
#[test]
10751098
fn slash_mention_dispatches_command_and_inserts_at() {
10761099
use crossterm::event::KeyCode;

0 commit comments

Comments
 (0)