Add bracketed paste mode support for handling pasted text as verbatim input

This commit is contained in:
2026-03-05 20:04:20 -05:00
parent cac7140c8b
commit e31e27f935
7 changed files with 95 additions and 24 deletions

View File

@@ -61,6 +61,10 @@ impl ViMode for ViInsert {
raw_seq: String::new(),
flags: Default::default(),
}),
E(K::Verbatim(seq), _) => {
self.pending_cmd.set_verb(VerbCmd(1, Verb::Insert(seq.to_string())));
self.register_and_return()
}
E(K::Char('W'), M::CTRL) => {
self.pending_cmd.set_verb(VerbCmd(1, Verb::Delete));
self.pending_cmd.set_motion(MotionCmd(

View File

@@ -4,11 +4,19 @@ use crate::readline::vicmd::{CmdFlags, RegisterName, To, Verb, VerbCmd, ViCmd};
#[derive(Default, Clone, Debug)]
pub struct ViVerbatim {
pending_seq: String,
sent_cmd: Vec<ViCmd>,
repeat_count: u16,
read_one: bool
}
impl ViVerbatim {
pub fn read_one() -> Self {
Self {
read_one: true,
..Self::default()
}
}
pub fn new() -> Self {
Self::default()
}
@@ -23,7 +31,7 @@ impl ViVerbatim {
impl ViMode for ViVerbatim {
fn handle_key(&mut self, key: E) -> Option<ViCmd> {
match key {
E(K::Verbatim(seq), _mods) => {
E(K::Verbatim(seq), _mods) if self.read_one => {
log::debug!("Received verbatim key sequence: {:?}", seq);
let cmd = ViCmd {
register: RegisterName::default(),
@@ -35,6 +43,22 @@ impl ViMode for ViVerbatim {
self.sent_cmd.push(cmd.clone());
Some(cmd)
}
E(K::Verbatim(seq), _mods) => {
self.pending_seq.push_str(&seq);
None
}
E(K::BracketedPasteEnd, _mods) => {
log::debug!("Received verbatim paste: {:?}", self.pending_seq);
let cmd = ViCmd {
register: RegisterName::default(),
verb: Some(VerbCmd(1, Verb::Insert(self.pending_seq.clone()))),
motion: None,
raw_seq: std::mem::take(&mut self.pending_seq),
flags: CmdFlags::EXIT_CUR_MODE,
};
self.sent_cmd.push(cmd.clone());
Some(cmd)
}
_ => common_cmds(key),
}
}