Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/keymap/vi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,15 +908,19 @@ impl<'a, W: Write> Vi<'a, W> {
(_, ReverseRepeat, Some((c, RightUntil))) => (Key::Char(c), LeftUntil),
(_, ReverseRepeat, Some((c, LeftAt))) => (Key::Char(c), RightAt),
(_, ReverseRepeat, Some((c, RightAt))) => (Key::Char(c), LeftAt),
// repeat with no last_char_movement, invalid
(_, Repeat, None) | (_, ReverseRepeat, None) => {
self.normal_mode_abort();
return Ok(());
}
// pass valid keys through as is
(Key::Char(c), _, _) => {
// store last command info
self.last_char_movement = Some((c, movement));
self.current_command.push(key);
(key, movement)
}
// all other combinations are invalid, abort. This includes repeats with no
// last_char_movement stored, and non char key presses.
// all other combinations are invalid, abort
_ => {
self.normal_mode_abort();
return Ok(());
Expand Down Expand Up @@ -3714,4 +3718,21 @@ mod tests {
assert_eq!(res.is_ok(), true);
assert_eq!(map.ed.current_buffer().to_string(), "not empt".to_string());
}

#[test]
/// repeat char move with no last char
fn repeat_char_move_no_char() {
let mut context = Context::new();
let out = Vec::new();
let ed = Editor::new(out, "prompt".to_owned(), &mut context).unwrap();
let mut map = Vi::new(ed);
map.ed.insert_str_after_cursor("abc defg").unwrap();

simulate_keys!(map, [
Esc,
Char('$'),
Char(';'),
]);
assert_eq!(map.ed.cursor(), 7);
}
}