summaryrefslogtreecommitdiff
path: root/helix-core/src/register.rs
blob: 0176d23e31d4ee814a7f84aefdb9ac7218e0a3f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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()));

/// Read register values.
pub fn get(register_name: char) -> Option<Vec<String>> {
    let registry = REGISTRY.read().unwrap();
    registry.get(&register_name).cloned() // TODO: no cloning
}

/// Read register values.
// restoring: bool
pub fn set(register_name: char, values: Vec<String>) {
    let mut registry = REGISTRY.write().unwrap();
    registry.insert(register_name, values);
}