1use editor::CursorShape;
2use gpui::keymap::Context;
3use serde::Deserialize;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)]
6pub enum Mode {
7 Normal(NormalState),
8 Insert,
9}
10
11impl Mode {
12 pub fn cursor_shape(&self) -> CursorShape {
13 match self {
14 Mode::Normal(_) => CursorShape::Block,
15 Mode::Insert => CursorShape::Bar,
16 }
17 }
18
19 pub fn keymap_context_layer(&self) -> Context {
20 let mut context = Context::default();
21 context.map.insert(
22 "vim_mode".to_string(),
23 match self {
24 Self::Normal(_) => "normal",
25 Self::Insert => "insert",
26 }
27 .to_string(),
28 );
29
30 match self {
31 Self::Normal(normal_state) => normal_state.set_context(&mut context),
32 _ => {}
33 }
34 context
35 }
36
37 pub fn normal() -> Mode {
38 Mode::Normal(Default::default())
39 }
40}
41
42impl Default for Mode {
43 fn default() -> Self {
44 Self::Normal(Default::default())
45 }
46}
47
48#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)]
49pub enum NormalState {
50 None,
51 GPrefix,
52}
53
54impl NormalState {
55 pub fn set_context(&self, context: &mut Context) {
56 let submode = match self {
57 Self::GPrefix => Some("g"),
58 _ => None,
59 };
60
61 if let Some(submode) = submode {
62 context
63 .map
64 .insert("vim_submode".to_string(), submode.to_string());
65 }
66 }
67}
68
69impl Default for NormalState {
70 fn default() -> Self {
71 NormalState::None
72 }
73}