Early implementation of Verbatim mode
This commit is contained in:
@@ -64,6 +64,10 @@ impl ViMode for ViInsert {
|
||||
));
|
||||
self.register_and_return()
|
||||
}
|
||||
E(K::Char('V'), M::CTRL) => {
|
||||
self.pending_cmd.set_verb(VerbCmd(1, Verb::VerbatimMode));
|
||||
self.register_and_return()
|
||||
}
|
||||
E(K::Char('H'), M::CTRL) | E(K::Backspace, M::NONE) => {
|
||||
self.pending_cmd.set_verb(VerbCmd(1, Verb::Delete));
|
||||
self
|
||||
|
||||
@@ -13,12 +13,14 @@ pub mod normal;
|
||||
pub mod replace;
|
||||
pub mod visual;
|
||||
pub mod ex;
|
||||
pub mod verbatim;
|
||||
|
||||
pub use ex::ViEx;
|
||||
pub use insert::ViInsert;
|
||||
pub use normal::ViNormal;
|
||||
pub use replace::ViReplace;
|
||||
pub use visual::ViVisual;
|
||||
pub use verbatim::ViVerbatim;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum ModeReport {
|
||||
@@ -27,6 +29,7 @@ pub enum ModeReport {
|
||||
Ex,
|
||||
Visual,
|
||||
Replace,
|
||||
Verbatim,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
@@ -38,6 +41,7 @@ impl Display for ModeReport {
|
||||
ModeReport::Ex => write!(f, "COMMAND"),
|
||||
ModeReport::Visual => write!(f, "VISUAL"),
|
||||
ModeReport::Replace => write!(f, "REPLACE"),
|
||||
ModeReport::Verbatim => write!(f, "VERBATIM"),
|
||||
ModeReport::Unknown => write!(f, "UNKNOWN"),
|
||||
}
|
||||
}
|
||||
|
||||
66
src/readline/vimode/verbatim.rs
Normal file
66
src/readline/vimode/verbatim.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
use super::{common_cmds, CmdReplay, ModeReport, ViMode};
|
||||
use crate::readline::keys::{KeyCode as K, KeyEvent as E, ModKeys as M};
|
||||
use crate::readline::register::Register;
|
||||
use crate::readline::vicmd::{
|
||||
CmdFlags, Direction, Motion, MotionCmd, RegisterName, To, Verb, VerbCmd, ViCmd, Word
|
||||
};
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct ViVerbatim {
|
||||
sent_cmd: Vec<ViCmd>,
|
||||
repeat_count: u16
|
||||
}
|
||||
|
||||
impl ViVerbatim {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
pub fn with_count(self, repeat_count: u16) -> Self {
|
||||
Self { repeat_count, ..self }
|
||||
}
|
||||
}
|
||||
|
||||
impl ViMode for ViVerbatim {
|
||||
fn handle_key(&mut self, key: E) -> Option<ViCmd> {
|
||||
match key {
|
||||
E(K::Verbatim(seq),_mods) => {
|
||||
let cmd = ViCmd { register: RegisterName::default(),
|
||||
verb: Some(VerbCmd(1,Verb::Insert(seq.to_string()))),
|
||||
motion: None,
|
||||
raw_seq: seq.to_string(),
|
||||
flags: CmdFlags::EXIT_CUR_MODE
|
||||
};
|
||||
self.sent_cmd.push(cmd.clone());
|
||||
Some(cmd)
|
||||
}
|
||||
_ => common_cmds(key),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_repeatable(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn as_replay(&self) -> Option<CmdReplay> {
|
||||
Some(CmdReplay::mode(self.sent_cmd.clone(), self.repeat_count))
|
||||
}
|
||||
|
||||
fn cursor_style(&self) -> String {
|
||||
"\x1b[6 q".to_string()
|
||||
}
|
||||
fn pending_seq(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
fn move_cursor_on_undo(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn clamp_cursor(&self) -> bool {
|
||||
false
|
||||
}
|
||||
fn hist_scroll_start_pos(&self) -> Option<To> {
|
||||
Some(To::End)
|
||||
}
|
||||
fn report_mode(&self) -> ModeReport {
|
||||
ModeReport::Insert
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user