adding ctrl+f ctrl+b emacs style mapping

This commit is contained in:
pap
2025-08-09 12:01:07 +01:00
parent e87974ae83
commit f033740077
+38
View File
@@ -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");