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.
This commit is contained in:
Kazuhiro Sera
2025-08-20 01:34:52 +09:00
committed by GitHub
parent e7e5fe91c8
commit 16f11a89d8

View File

@@ -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;