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