Add word and line movement in vim normal mode

Add jump to start and end of the document
Move vim tests to relevant vim files
Rename VimTestAppContext to VimTestContext for brevity
Improve VimTestContext assertions to pretty print locations when selection position assertion panics
This commit is contained in:
Keith Simmons 2022-03-27 17:58:28 -07:00
parent 3ae5fc74c9
commit a7a52ef3f7
10 changed files with 766 additions and 278 deletions

View file

@ -3,14 +3,14 @@ use gpui::keymap::Context;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Mode {
Normal,
Normal(NormalState),
Insert,
}
impl Mode {
pub fn cursor_shape(&self) -> CursorShape {
match self {
Mode::Normal => CursorShape::Block,
Mode::Normal(_) => CursorShape::Block,
Mode::Insert => CursorShape::Bar,
}
}
@ -20,17 +20,53 @@ impl Mode {
context.map.insert(
"vim_mode".to_string(),
match self {
Self::Normal => "normal",
Self::Normal(_) => "normal",
Self::Insert => "insert",
}
.to_string(),
);
match self {
Self::Normal(normal_state) => normal_state.set_context(&mut context),
_ => {}
}
context
}
pub fn normal() -> Mode {
Mode::Normal(Default::default())
}
}
impl Default for Mode {
fn default() -> Self {
Self::Normal
Self::Normal(Default::default())
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NormalState {
None,
GPrefix,
}
impl NormalState {
pub fn set_context(&self, context: &mut Context) {
let sub_mode = match self {
Self::GPrefix => Some("g"),
_ => None,
};
if let Some(sub_mode) = sub_mode {
context
.map
.insert("vim_sub_mode".to_string(), sub_mode.to_string());
}
}
}
impl Default for NormalState {
fn default() -> Self {
NormalState::None
}
}