Skip to content

Commit e112800

Browse files
vim replace mode
1 parent 9c66faf commit e112800

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/vim.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crossterm::{
88
};
99
use ratatui::{
1010
backend::CrosstermBackend,
11-
style::{Color, Modifier, Style},
11+
style::{Color, Modifier, Style, Stylize},
1212
text::Line,
1313
widgets::{Block, Borders},
1414
Terminal,
@@ -21,6 +21,7 @@ pub enum Mode {
2121
Normal,
2222
Insert,
2323
Visual,
24+
Replace,
2425
Operator(char),
2526
}
2627

@@ -30,6 +31,7 @@ impl Mode {
3031
Self::Normal => "type i to enter insert mode",
3132
Self::Insert => "type Esc to back to normal mode",
3233
Self::Visual => "type y to yank, type d to delete, type Esc to back to normal mode",
34+
Self::Replace => "type character to replace underlined",
3335
Self::Operator(_) => "move cursor to apply operator",
3436
};
3537
let title = format!("{} MODE ({})", self, help);
@@ -41,9 +43,10 @@ impl Mode {
4143
Self::Normal => Color::Reset,
4244
Self::Insert => Color::LightBlue,
4345
Self::Visual => Color::LightYellow,
46+
Self::Replace => Color::LightGreen,
4447
Self::Operator(_) => Color::LightGreen,
4548
};
46-
Style::default().add_modifier(Modifier::SLOW_BLINK)
49+
Style::default().add_modifier(Modifier::REVERSED)
4750
}
4851
}
4952

@@ -53,6 +56,7 @@ impl fmt::Display for Mode {
5356
Self::Normal => write!(f, "NORMAL"),
5457
Self::Insert => write!(f, "INSERT"),
5558
Self::Visual => write!(f, "VISUAL"),
59+
Self::Replace => write!(f, "REPLACE"),
5660
Self::Operator(c) => write!(f, "OPERATOR({})", c),
5761
}
5862
}
@@ -119,6 +123,9 @@ impl Vim {
119123
textarea.redo();
120124
return Transition::Mode(Mode::Normal);
121125
},
126+
Input { key: Key::Char('r'), ctrl: false, .. } => {
127+
return Transition::Mode(Mode::Replace);
128+
},
122129
Input { key: Key::Char('x'), .. } => {
123130
textarea.delete_next_char();
124131
return Transition::Mode(Mode::Normal);
@@ -238,6 +245,14 @@ impl Vim {
238245
},
239246
}
240247
},
248+
Mode::Replace => match input {
249+
Input { key: Key::Esc, .. } | Input { key: Key::Char('c'), ctrl: true, .. } => Transition::Mode(Mode::Normal),
250+
input => {
251+
textarea.delete_str(1);
252+
textarea.input(input);
253+
Transition::Mode(Mode::Normal)
254+
},
255+
},
241256
}
242257
}
243258
}

0 commit comments

Comments
 (0)