feat: add counted motions in Normal and Visual modes

This commit is contained in:
Valdemar Lorenzen
2026-10-08 12:19:38 +02:00
parent bd78656691
commit 38006c1eca
4 changed files with 335 additions and 78 deletions
+32 -1
View File
@@ -326,7 +326,7 @@ fn draw(frame: &mut Frame, editor: &Editor, top: &mut usize, left: &mut usize) {
.map(|c| if c.is_control() { '�' } else { c })
.collect();
let status = format!(
" {} {}{} {}:{}{}",
" {} {}{} {}:{}{}{}",
editor.mode(),
path,
if editor.dirty() { " [+]" } else { "" },
@@ -336,6 +336,11 @@ fn draw(frame: &mut Frame, editor: &Editor, top: &mut usize, left: &mut usize) {
format!(" {} selections", editor.selection_count())
} else {
String::new()
},
if let Some(count) = editor.count() {
format!(" count: {count}")
} else {
String::new()
}
);
frame.render_widget(
@@ -488,6 +493,32 @@ mod tests {
.join("\n")
}
#[test]
fn pending_motion_count_is_visible_and_escape_cancels_without_moving() {
let mut editor = Editor::open(None, vec![]).unwrap();
editor
.apply(vec![crate::editor::Effect::Replace(["row"; 12].join("\n"))])
.unwrap();
let mut terminal = Terminal::new(ratatui::backend::TestBackend::new(60, 6)).unwrap();
let (mut top, mut left) = (0, 0);
editor.handle(Input::Char('1'));
editor.handle(Input::Char('0'));
terminal
.draw(|frame| draw(frame, &editor, &mut top, &mut left))
.unwrap();
assert!(screen_text(&terminal).contains("count: 10"));
editor.handle(Input::Escape);
editor.handle(Input::Down);
terminal
.draw(|frame| draw(frame, &editor, &mut top, &mut left))
.unwrap();
assert!(!screen_text(&terminal).contains("count:"));
assert_eq!(
terminal.get_cursor_position().unwrap(),
ratatui::layout::Position::new(3, 1)
);
}
#[test]
fn gutter_tracks_scrolled_rows_without_scrolling_with_text() {
let mut editor = Editor::open(None, vec![]).unwrap();