feat: jump to a line with counted g
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
use vamp::editor::{Cursor, Editor, Effect, Input, Mode};
|
||||
fn editor() -> Editor {
|
||||
let mut editor = Editor::open(None, vec![]).unwrap();
|
||||
editor
|
||||
.apply(vec![Effect::Replace(
|
||||
"first\n e\u{301}second\n\tthird".into(),
|
||||
)])
|
||||
.unwrap();
|
||||
editor
|
||||
}
|
||||
fn keys(editor: &mut Editor, text: &str) {
|
||||
for key in text.chars() {
|
||||
editor.handle(Input::Char(key));
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn counted_g_is_one_based_clamps_and_leaves_bare_prefixes_intact() {
|
||||
let mut editor = editor();
|
||||
let revision = editor.text_revision();
|
||||
keys(&mut editor, "2g");
|
||||
assert_eq!(editor.cursor(), Cursor { row: 1, column: 2 });
|
||||
assert_eq!(editor.count(), None);
|
||||
keys(&mut editor, "999999999999999999999999999999999g");
|
||||
assert_eq!(editor.cursor(), Cursor { row: 2, column: 1 });
|
||||
keys(&mut editor, "1g");
|
||||
assert_eq!(editor.cursor().row, 0);
|
||||
keys(&mut editor, "gb");
|
||||
assert_eq!(editor.cursor().row, 2);
|
||||
keys(&mut editor, "gt");
|
||||
assert_eq!(editor.cursor().row, 0);
|
||||
assert_eq!(editor.text_revision(), revision);
|
||||
}
|
||||
#[test]
|
||||
fn counted_g_extends_visual_selection_and_respects_g_overrides() {
|
||||
let mut editor = editor();
|
||||
keys(&mut editor, "v3g");
|
||||
assert_eq!(editor.mode(), Mode::Visual);
|
||||
assert_eq!(editor.cursor(), Cursor { row: 2, column: 1 });
|
||||
assert_eq!(editor.selections()[0].start, Cursor { row: 0, column: 0 });
|
||||
editor.handle(Input::Escape);
|
||||
keys(&mut editor, "gt");
|
||||
editor.bind("normal", "g", None).unwrap();
|
||||
keys(&mut editor, "2g");
|
||||
assert_eq!(editor.cursor().row, 0);
|
||||
editor
|
||||
.bind("normal", "g", Some("core.down".into()))
|
||||
.unwrap();
|
||||
keys(&mut editor, "2g");
|
||||
assert_eq!(editor.cursor().row, 2);
|
||||
}
|
||||
Reference in New Issue
Block a user