Add c and d operators to vim normal mode

Extracted motions from normal mode
Changed vim_submode to be vim_operator to enable better composition of operators
This commit is contained in:
Keith Simmons 2022-04-15 16:00:44 -07:00
parent 670757e5c9
commit 63278041e1
10 changed files with 862 additions and 433 deletions

View file

@ -6,7 +6,7 @@ use language::{Point, Selection};
use util::test::marked_text;
use workspace::{WorkspaceHandle, WorkspaceParams};
use crate::*;
use crate::{state::Operator, *};
pub struct VimTestContext<'a> {
cx: &'a mut gpui::TestAppContext,
@ -100,7 +100,12 @@ impl<'a> VimTestContext<'a> {
}
pub fn mode(&mut self) -> Mode {
self.cx.update(|cx| cx.global::<VimState>().mode)
self.cx.read(|cx| cx.global::<Vim>().state.mode)
}
pub fn active_operator(&mut self) -> Option<Operator> {
self.cx
.read(|cx| cx.global::<Vim>().state.operator_stack.last().copied())
}
pub fn editor_text(&mut self) -> String {
@ -119,12 +124,23 @@ impl<'a> VimTestContext<'a> {
.dispatch_keystroke(self.window_id, keystroke, input, false);
}
pub fn simulate_keystrokes(&mut self, keystroke_texts: &[&str]) {
pub fn simulate_keystrokes<const COUNT: usize>(&mut self, keystroke_texts: [&str; COUNT]) {
for keystroke_text in keystroke_texts.into_iter() {
self.simulate_keystroke(keystroke_text);
}
}
pub fn set_state(&mut self, text: &str, mode: Mode) {
self.cx
.update(|cx| Vim::update(cx, |vim, cx| vim.switch_mode(mode, cx)));
self.editor.update(self.cx, |editor, cx| {
let (unmarked_text, markers) = marked_text(&text);
editor.set_text(unmarked_text, cx);
let cursor_offset = markers[0];
editor.replace_selections_with(cx, |map| cursor_offset.to_display_point(map));
})
}
pub fn assert_newest_selection_head_offset(&mut self, expected_offset: usize) {
let actual_head = self.newest_selection().head();
let (actual_offset, expected_head) = self.editor.update(self.cx, |editor, cx| {
@ -171,6 +187,21 @@ impl<'a> VimTestContext<'a> {
actual_position_text, expected_position_text
)
}
pub fn assert_binding<const COUNT: usize>(
&mut self,
keystrokes: [&str; COUNT],
initial_state: &str,
initial_mode: Mode,
state_after: &str,
mode_after: Mode,
) {
self.set_state(initial_state, initial_mode);
self.simulate_keystrokes(keystrokes);
self.assert_editor_state(state_after);
assert_eq!(self.mode(), mode_after);
assert_eq!(self.active_operator(), None);
}
}
impl<'a> Deref for VimTestContext<'a> {