Compare commits

...

3 Commits

Author SHA1 Message Date
pap
6eda9fc463 fix test fmt 2025-08-09 17:04:08 +01:00
pap
ff652a9c65 unify tests 2025-08-09 16:57:33 +01:00
pap
f033740077 adding ctrl+f ctrl+b emacs style mapping 2025-08-09 12:01:07 +01:00

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();
}
@@ -889,6 +899,7 @@ mod tests {
let mut t = ta_with("a👍b");
t.set_cursor(t.text().len());
// Test moving left
t.move_cursor_left(); // before 'b'
let after_first_left = t.cursor();
t.move_cursor_left(); // before '👍'
@@ -900,11 +911,31 @@ mod tests {
assert!(after_second_left < after_first_left);
assert!(after_third_left < after_second_left);
// Move right back to end safely
// Test moving right back to end safely
t.move_cursor_right();
t.move_cursor_right();
t.move_cursor_right();
assert_eq!(t.cursor(), t.text().len());
// Test using ctrl-f and ctrl-b for graphemes (byte indices)
use crossterm::event::KeyCode;
use crossterm::event::KeyEvent;
use crossterm::event::KeyModifiers;
let mut t = ta_with("a👍b");
t.set_cursor(0);
t.input(KeyEvent::new(KeyCode::Char('f'), KeyModifiers::CONTROL)); // after 'a'
assert_eq!(t.cursor(), 1);
t.input(KeyEvent::new(KeyCode::Char('f'), KeyModifiers::CONTROL)); // after '👍' (4-byte emoji)
assert_eq!(t.cursor(), 5);
t.input(KeyEvent::new(KeyCode::Char('f'), KeyModifiers::CONTROL)); // after 'b' (end)
assert_eq!(t.cursor(), 6);
t.input(KeyEvent::new(KeyCode::Char('b'), KeyModifiers::CONTROL)); // back to after '👍'
assert_eq!(t.cursor(), 5);
t.input(KeyEvent::new(KeyCode::Char('b'), KeyModifiers::CONTROL)); // back to after 'a'
assert_eq!(t.cursor(), 1);
t.input(KeyEvent::new(KeyCode::Char('b'), KeyModifiers::CONTROL)); // back to start
assert_eq!(t.cursor(), 0);
}
#[test]