aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/register.rs
diff options
context:
space:
mode:
authorMichael Davis2023-07-10 23:48:29 +0000
committerBlaž Hrastnik2023-07-31 06:05:38 +0000
commitbaceb02a090fe711ad772d855635bc590826fa53 (patch)
tree9bb4eecbce2e7c84caf707f33ff39d7a2dcf7102 /helix-core/src/register.rs
parent0f19f282cfa49d441f58a8e2540a6b24efe1b769 (diff)
Use refactored Registers type
This is an unfortunately noisy change: we need to update virtually all callsites that access the registers. For reads this means passing in the Editor and for writes this means handling potential failure when we can't write to a clipboard register.
Diffstat (limited to 'helix-core/src/register.rs')
-rw-r--r--helix-core/src/register.rs89
1 files changed, 0 insertions, 89 deletions
diff --git a/helix-core/src/register.rs b/helix-core/src/register.rs
deleted file mode 100644
index df68a759..00000000
--- a/helix-core/src/register.rs
+++ /dev/null
@@ -1,89 +0,0 @@
-use std::collections::HashMap;
-
-#[derive(Debug)]
-pub struct Register {
- name: char,
- values: Vec<String>,
-}
-
-impl Register {
- pub const fn new(name: char) -> Self {
- Self {
- name,
- values: Vec::new(),
- }
- }
-
- pub fn new_with_values(name: char, values: Vec<String>) -> Self {
- Self { name, values }
- }
-
- pub const fn name(&self) -> char {
- self.name
- }
-
- pub fn read(&self) -> &[String] {
- &self.values
- }
-
- pub fn write(&mut self, values: Vec<String>) {
- self.values = values;
- }
-
- pub fn push(&mut self, value: String) {
- self.values.push(value);
- }
-}
-
-/// Currently just wraps a `HashMap` of `Register`s
-#[derive(Debug, Default)]
-pub struct Registers {
- inner: HashMap<char, Register>,
-}
-
-impl Registers {
- pub fn get(&self, name: char) -> Option<&Register> {
- self.inner.get(&name)
- }
-
- pub fn read(&self, name: char) -> Option<&[String]> {
- self.get(name).map(|reg| reg.read())
- }
-
- pub fn write(&mut self, name: char, values: Vec<String>) {
- if name != '_' {
- self.inner
- .insert(name, Register::new_with_values(name, values));
- }
- }
-
- pub fn push(&mut self, name: char, value: String) {
- if name != '_' {
- if let Some(r) = self.inner.get_mut(&name) {
- r.push(value);
- } else {
- self.write(name, vec![value]);
- }
- }
- }
-
- pub fn first(&self, name: char) -> Option<&String> {
- self.read(name).and_then(|entries| entries.first())
- }
-
- pub fn last(&self, name: char) -> Option<&String> {
- self.read(name).and_then(|entries| entries.last())
- }
-
- pub fn inner(&self) -> &HashMap<char, Register> {
- &self.inner
- }
-
- pub fn clear(&mut self) {
- self.inner.clear();
- }
-
- pub fn remove(&mut self, name: char) -> Option<Register> {
- self.inner.remove(&name)
- }
-}