Commit 8422f85c authored by Matthew Nicholson's avatar Matthew Nicholson
Browse files

support 'C' command

parent adfef116
......@@ -79,14 +79,21 @@ impl<'a, W: Write> Vi<'a, W> {
fn set_mode(&mut self, mode: Mode) {
use self::Mode::*;
self.set_mode_preserve_last(mode);
if mode == Insert {
self.last_count = 0;
self.last_command.clear();
}
}
fn set_mode_preserve_last(&mut self, mode: Mode) {
use self::Mode::*;
self.ed.no_eol = mode == Normal;
self.movement_reset = mode != Insert;
self.mode_stack.push(mode);
if mode == Insert {
self.last_count = 0;
self.last_command.clear();
self.ed.current_buffer_mut().start_undo_group();
}
}
......@@ -304,6 +311,17 @@ impl<'a, W: Write> Vi<'a, W> {
self.ed.delete_all_after_cursor()
}
Key::Char('C') => {
// update the last command state
self.last_insert = None;
self.last_command.clear();
self.last_command.push(key);
self.count = 0;
self.last_count = 0;
self.set_mode_preserve_last(Insert);
self.ed.delete_all_after_cursor()
}
Key::Char('.') => {
// repeat the last command
self.count = match (self.count, self.last_count) {
......@@ -1320,6 +1338,49 @@ mod tests {
assert_eq!(String::from(map), "");
}
#[test]
/// test change until end of line
fn change_until_end_shift_c() {
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("change").unwrap();
simulate_keys!(map, [
Esc,
Char('0'),
Char('C'),
Char('o'),
Char('k'),
]);
assert_eq!(map.ed.cursor(), 2);
assert_eq!(String::from(map), "ok");
}
#[test]
/// test change until end of line
fn change_until_end_from_middle_shift_c() {
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("change").unwrap();
simulate_keys!(map, [
Esc,
Char('0'),
Char('2'),
Char('l'),
Char('C'),
Char(' '),
Char('o'),
Char('k'),
Esc,
]);
assert_eq!(String::from(map), "ch ok");
}
#[test]
/// undo with counts
fn test_undo_with_counts() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment