aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-10-06 07:00:23 +0000
committerBlaž Hrastnik2020-10-13 14:13:56 +0000
commit1dba0f2b1ccc0c6a29e05876b7b7153373221f87 (patch)
tree2114ae0a23fb379c57b7ad1de491fa8406cbaffe /helix-core
parenteba5b1ef3329bef35fe387b03bdf2f32cdb34761 (diff)
Simple yank/paste registers.
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/lib.rs1
-rw-r--r--helix-core/src/register.rs21
-rw-r--r--helix-core/src/selection.rs3
-rw-r--r--helix-core/src/transaction.rs2
4 files changed, 25 insertions, 2 deletions
diff --git a/helix-core/src/lib.rs b/helix-core/src/lib.rs
index 9bc5d003..4a7a2dd4 100644
--- a/helix-core/src/lib.rs
+++ b/helix-core/src/lib.rs
@@ -3,6 +3,7 @@ pub mod graphemes;
mod history;
pub mod macros;
mod position;
+pub mod register;
pub mod selection;
pub mod state;
pub mod syntax;
diff --git a/helix-core/src/register.rs b/helix-core/src/register.rs
new file mode 100644
index 00000000..0be0ce89
--- /dev/null
+++ b/helix-core/src/register.rs
@@ -0,0 +1,21 @@
+use crate::Tendril;
+use once_cell::sync::Lazy;
+use std::{collections::HashMap, sync::RwLock};
+
+// TODO: could be an instance on Editor
+static REGISTRY: Lazy<RwLock<HashMap<char, Vec<String>>>> =
+ Lazy::new(|| RwLock::new(HashMap::new()));
+
+pub fn get(register: char) -> Option<Vec<String>> {
+ let registry = REGISTRY.read().unwrap();
+
+ // TODO: no cloning
+ registry.get(&register).cloned()
+}
+
+// restoring: bool
+pub fn set(register: char, values: Vec<String>) {
+ let mut registry = REGISTRY.write().unwrap();
+
+ registry.insert(register, values);
+}
diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs
index 2251c77f..bc677330 100644
--- a/helix-core/src/selection.rs
+++ b/helix-core/src/selection.rs
@@ -110,7 +110,8 @@ impl Range {
#[inline]
pub fn fragment<'a>(&'a self, text: &'a RopeSlice) -> Cow<'a, str> {
- Cow::from(text.slice(self.from()..self.to()))
+ // end inclusive
+ Cow::from(text.slice(self.from()..self.to() + 1))
}
}
diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs
index 13c0c50f..33612ecf 100644
--- a/helix-core/src/transaction.rs
+++ b/helix-core/src/transaction.rs
@@ -445,7 +445,7 @@ impl Transaction {
/// Generate a transaction with a change per selection range.
pub fn change_by_selection<F>(state: &State, f: F) -> Self
where
- F: Fn(&Range) -> Change,
+ F: FnMut(&Range) -> Change,
{
Self::change(state, state.selection.ranges().iter().map(f))
}