ViEditor: Implement put/yank registers
This commit is contained in:
parent
04c96f39c5
commit
9278e7d0c4
2 changed files with 18 additions and 8 deletions
|
|
@ -15,7 +15,7 @@ fontdb = { version = "0.16.0", default-features = false }
|
||||||
hashbrown = { version = "0.14.1", optional = true, default-features = false }
|
hashbrown = { version = "0.14.1", optional = true, default-features = false }
|
||||||
libm = "0.2.8"
|
libm = "0.2.8"
|
||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
modit = { version = "0.1.1", optional = true }
|
modit = { version = "0.1.2", optional = true }
|
||||||
rangemap = "1.4.0"
|
rangemap = "1.4.0"
|
||||||
rustc-hash = { version = "1.1.0", default-features = false }
|
rustc-hash = { version = "1.1.0", default-features = false }
|
||||||
rustybuzz = { version = "0.11.0", default-features = false, features = ["libm"] }
|
rustybuzz = { version = "0.11.0", default-features = false, features = ["libm"] }
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use alloc::string::String;
|
use alloc::{collections::BTreeMap, string::String};
|
||||||
use core::cmp;
|
use core::cmp;
|
||||||
use modit::{Event, Key, Motion, Parser, TextObject, WordIter};
|
use modit::{Event, Key, Motion, Parser, TextObject, WordIter};
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
@ -155,6 +155,7 @@ pub struct ViEditor<'a> {
|
||||||
editor: SyntaxEditor<'a>,
|
editor: SyntaxEditor<'a>,
|
||||||
parser: ViParser,
|
parser: ViParser,
|
||||||
passthrough: bool,
|
passthrough: bool,
|
||||||
|
registers: BTreeMap<char, (Selection, String)>,
|
||||||
search_opt: Option<(String, bool)>,
|
search_opt: Option<(String, bool)>,
|
||||||
commands: cosmic_undo_2::Commands<Change>,
|
commands: cosmic_undo_2::Commands<Change>,
|
||||||
changed: bool,
|
changed: bool,
|
||||||
|
|
@ -166,6 +167,7 @@ impl<'a> ViEditor<'a> {
|
||||||
editor,
|
editor,
|
||||||
parser: ViParser::new(),
|
parser: ViParser::new(),
|
||||||
passthrough: false,
|
passthrough: false,
|
||||||
|
registers: BTreeMap::new(),
|
||||||
search_opt: None,
|
search_opt: None,
|
||||||
commands: cosmic_undo_2::Commands::new(),
|
commands: cosmic_undo_2::Commands::new(),
|
||||||
changed: false,
|
changed: false,
|
||||||
|
|
@ -378,16 +380,18 @@ impl<'a> Edit for ViEditor<'a> {
|
||||||
finish_change(editor, &mut self.commands, &mut self.changed);
|
finish_change(editor, &mut self.commands, &mut self.changed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Event::Copy => {
|
|
||||||
log::info!("TODO");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Event::Delete => Action::Delete,
|
Event::Delete => Action::Delete,
|
||||||
Event::Escape => Action::Escape,
|
Event::Escape => Action::Escape,
|
||||||
Event::Insert(c) => Action::Insert(c),
|
Event::Insert(c) => Action::Insert(c),
|
||||||
Event::NewLine => Action::Enter,
|
Event::NewLine => Action::Enter,
|
||||||
Event::Paste => {
|
Event::Put { register, after } => {
|
||||||
log::info!("TODO");
|
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;
|
return;
|
||||||
}
|
}
|
||||||
Event::Redraw => {
|
Event::Redraw => {
|
||||||
|
|
@ -473,6 +477,12 @@ impl<'a> Edit for ViEditor<'a> {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Event::Yank { register } => {
|
||||||
|
if let Some(data) = editor.copy_selection() {
|
||||||
|
self.registers.insert(register, (editor.selection(), data));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
Event::Motion(motion) => {
|
Event::Motion(motion) => {
|
||||||
match motion {
|
match motion {
|
||||||
Motion::Around => {
|
Motion::Around => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue