Skip to content

Commit

Permalink
ViEditor: Implement put/yank registers
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Nov 30, 2023
1 parent 04c96f3 commit 9278e7d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
24 changes: 17 additions & 7 deletions src/edit/vi.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -155,6 +155,7 @@ pub struct ViEditor<'a> {
editor: SyntaxEditor<'a>,
parser: ViParser,
passthrough: bool,
registers: BTreeMap<char, (Selection, String)>,
search_opt: Option<(String, bool)>,
commands: cosmic_undo_2::Commands<Change>,
changed: bool,
Expand All @@ -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,
Expand Down Expand Up @@ -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 } => {

Check warning on line 387 in src/edit/vi.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `after`

warning: unused variable: `after` --> src/edit/vi.rs:387:40 | 387 | Event::Put { register, after } => { | ^^^^^ help: try ignoring the field: `after: _` | = note: `#[warn(unused_variables)]` on by default
if let Some((selection, data)) = self.registers.get(&register) {

Check warning on line 388 in src/edit/vi.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `selection`

warning: unused variable: `selection` --> src/edit/vi.rs:388:34 | 388 | if let Some((selection, data)) = self.registers.get(&register) { | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_selection`
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 => {
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 9278e7d

Please sign in to comment.