diff --git a/Cargo.toml b/Cargo.toml index e76caaecf2..8951f2f2f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ fontdb = { version = "0.16.0", default-features = false } hashbrown = { version = "0.14.1", optional = true, default-features = false } libm = "0.2.8" log = "0.4.20" -modit = { version = "0.1.1", optional = true } +modit = { version = "0.1.2", optional = true } rangemap = "1.4.0" rustc-hash = { version = "1.1.0", default-features = false } rustybuzz = { version = "0.11.0", default-features = false, features = ["libm"] } diff --git a/src/edit/vi.rs b/src/edit/vi.rs index e52bddbbc5..c033350ccf 100644 --- a/src/edit/vi.rs +++ b/src/edit/vi.rs @@ -1,4 +1,4 @@ -use alloc::string::String; +use alloc::{collections::BTreeMap, string::String}; use core::cmp; use modit::{Event, Key, Motion, Parser, TextObject, WordIter}; use unicode_segmentation::UnicodeSegmentation; @@ -155,6 +155,7 @@ pub struct ViEditor<'a> { editor: SyntaxEditor<'a>, parser: ViParser, passthrough: bool, + registers: BTreeMap, search_opt: Option<(String, bool)>, commands: cosmic_undo_2::Commands, changed: bool, @@ -166,6 +167,7 @@ impl<'a> ViEditor<'a> { editor, parser: ViParser::new(), passthrough: false, + registers: BTreeMap::new(), search_opt: None, commands: cosmic_undo_2::Commands::new(), changed: false, @@ -378,16 +380,18 @@ impl<'a> Edit for ViEditor<'a> { finish_change(editor, &mut self.commands, &mut self.changed); return; } - Event::Copy => { - log::info!("TODO"); - return; - } Event::Delete => Action::Delete, Event::Escape => Action::Escape, Event::Insert(c) => Action::Insert(c), Event::NewLine => Action::Enter, - Event::Paste => { - log::info!("TODO"); + Event::Put { register, after } => { + if let Some((selection, data)) = self.registers.get(®ister) { + editor.start_change(); + editor.delete_selection(); + //TODO: handle after/before and select by line + editor.insert_string(data, None); + finish_change(editor, &mut self.commands, &mut self.changed); + } return; } Event::Redraw => { @@ -473,6 +477,12 @@ impl<'a> Edit for ViEditor<'a> { } return; } + Event::Yank { register } => { + if let Some(data) = editor.copy_selection() { + self.registers.insert(register, (editor.selection(), data)); + } + return; + } Event::Motion(motion) => { match motion { Motion::Around => {