feat(tui): add ctrl-b and ctrl-f shortcuts (#2260)
## Summary - support Ctrl-b and Ctrl-f to move the cursor left and right in the chat composer text area - test Ctrl-b/Ctrl-f cursor movements ## Testing - `just fmt` - `just fix` *(fails: `let` expressions in this position are unstable)* - `cargo test --all-features` *(fails: `let` expressions in this position are unstable)* ------ https://chatgpt.com/codex/tasks/task_i_689cbd1d7968832e876fff169891e486
This commit is contained in:
@@ -295,6 +295,20 @@ impl TextArea {
|
|||||||
} => {
|
} => {
|
||||||
self.move_cursor_right();
|
self.move_cursor_right();
|
||||||
}
|
}
|
||||||
|
KeyEvent {
|
||||||
|
code: KeyCode::Char('b'),
|
||||||
|
modifiers: KeyModifiers::CONTROL,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
self.move_cursor_left();
|
||||||
|
}
|
||||||
|
KeyEvent {
|
||||||
|
code: KeyCode::Char('f'),
|
||||||
|
modifiers: KeyModifiers::CONTROL,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
self.move_cursor_right();
|
||||||
|
}
|
||||||
// Some terminals send Alt+Arrow for word-wise movement:
|
// Some terminals send Alt+Arrow for word-wise movement:
|
||||||
// Option/Left -> Alt+Left (previous word start)
|
// Option/Left -> Alt+Left (previous word start)
|
||||||
// Option/Right -> Alt+Right (next word end)
|
// Option/Right -> Alt+Right (next word end)
|
||||||
@@ -908,6 +922,22 @@ mod tests {
|
|||||||
assert_eq!(t.cursor(), t.text().len());
|
assert_eq!(t.cursor(), t.text().len());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn control_b_and_f_move_cursor() {
|
||||||
|
use crossterm::event::KeyCode;
|
||||||
|
use crossterm::event::KeyEvent;
|
||||||
|
use crossterm::event::KeyModifiers;
|
||||||
|
|
||||||
|
let mut t = ta_with("abcd");
|
||||||
|
t.set_cursor(1);
|
||||||
|
|
||||||
|
t.input(KeyEvent::new(KeyCode::Char('f'), KeyModifiers::CONTROL));
|
||||||
|
assert_eq!(t.cursor(), 2);
|
||||||
|
|
||||||
|
t.input(KeyEvent::new(KeyCode::Char('b'), KeyModifiers::CONTROL));
|
||||||
|
assert_eq!(t.cursor(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cursor_vertical_movement_across_lines_and_bounds() {
|
fn cursor_vertical_movement_across_lines_and_bounds() {
|
||||||
let mut t = ta_with("short\nloooooooooong\nmid");
|
let mut t = ta_with("short\nloooooooooong\nmid");
|
||||||
|
|||||||
Reference in New Issue
Block a user