aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/commands.rs35
-rw-r--r--helix-view/src/keymap.rs2
2 files changed, 36 insertions, 1 deletions
diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs
index 9a6d2e5d..ca1e41c4 100644
--- a/helix-view/src/commands.rs
+++ b/helix-view/src/commands.rs
@@ -1,7 +1,7 @@
use helix_core::{
graphemes,
regex::Regex,
- selection,
+ register, selection,
state::{Direction, Granularity, Mode, State},
ChangeSet, Range, Selection, Tendril, Transaction,
};
@@ -443,3 +443,36 @@ pub fn undo(view: &mut View, _count: usize) {
pub fn redo(view: &mut View, _count: usize) {
view.history.redo(&mut view.state);
}
+
+// Yank / Paste
+
+pub fn yank(view: &mut View, _count: usize) {
+ // TODO: should selections be made end inclusive?
+ let values = view
+ .state
+ .selection()
+ .fragments(&view.state.doc().slice(..))
+ .map(|cow| cow.into_owned())
+ .collect();
+
+ register::set('"', values);
+}
+
+pub fn paste(view: &mut View, _count: usize) {
+ if let Some(values) = register::get('"') {
+ let repeat = std::iter::repeat(
+ values
+ .last()
+ .map(|value| Tendril::from_slice(value))
+ .unwrap(),
+ );
+
+ let mut values = values.into_iter().map(Tendril::from).chain(repeat);
+
+ let transaction = Transaction::change_by_selection(&view.state, |range| {
+ (range.head + 1, range.head + 1, Some(values.next().unwrap()))
+ });
+
+ transaction.apply(&mut view.state);
+ }
+}
diff --git a/helix-view/src/keymap.rs b/helix-view/src/keymap.rs
index e108324e..da5934eb 100644
--- a/helix-view/src/keymap.rs
+++ b/helix-view/src/keymap.rs
@@ -147,6 +147,8 @@ pub fn default() -> Keymaps {
vec![key!(';')] => commands::collapse_selection,
vec![key!('u')] => commands::undo,
vec![shift!('U')] => commands::redo,
+ vec![key!('y')] => commands::yank,
+ vec![key!('p')] => commands::paste,
vec![Key {
code: KeyCode::Esc,
modifiers: Modifiers::NONE