diff options
Diffstat (limited to 'helix-core/src')
-rw-r--r-- | helix-core/src/lib.rs | 1 | ||||
-rw-r--r-- | helix-core/src/register.rs | 21 | ||||
-rw-r--r-- | helix-core/src/selection.rs | 3 | ||||
-rw-r--r-- | helix-core/src/transaction.rs | 2 |
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(®ister).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)) } |