diff --git a/helix-view/src/register.rs b/helix-view/src/register.rs index 892d396f3..14fd3f7fa 100644 --- a/helix-view/src/register.rs +++ b/helix-view/src/register.rs @@ -2,7 +2,7 @@ use anyhow::Result; -use crate::Editor; +use crate::{document::SCRATCH_BUFFER_NAME, Editor}; /// A key-value store for saving sets of values. /// @@ -13,6 +13,7 @@ /// * Black hole (`_`): all values read and written are discarded /// * Selection indices (`#`): index number of each selection starting at 1 /// * Selection contents (`.`) +/// * Document path (`%`): filename of the current buffer #[derive(Debug, Default)] pub struct Registers { inner: HashMap>, @@ -36,6 +37,17 @@ pub fn read<'a>(&'a self, name: char, editor: &'a Editor) -> Option { + let doc = doc!(editor); + + let path = doc + .path() + .as_ref() + .map(|p| p.to_string_lossy()) + .unwrap_or_else(|| SCRATCH_BUFFER_NAME.into()); + + Some(RegisterValues::new(iter::once(path))) + } _ => self .inner .get(&name) @@ -46,7 +58,7 @@ pub fn read<'a>(&'a self, name: char, editor: &'a Editor) -> Option) -> Result<()> { match name { '_' => Ok(()), - '#' | '.' => Err(anyhow::anyhow!("Register {name} does not support writing")), + '#' | '.' | '%' => Err(anyhow::anyhow!("Register {name} does not support writing")), _ => { self.inner.insert(name, values); Ok(()) @@ -57,7 +69,7 @@ pub fn write(&mut self, name: char, values: Vec) -> Result<()> { pub fn push(&mut self, name: char, value: String) -> Result<()> { match name { '_' => Ok(()), - '#' | '.' => Err(anyhow::anyhow!("Register {name} does not support pushing")), + '#' | '.' | '%' => Err(anyhow::anyhow!("Register {name} does not support pushing")), _ => { self.inner.entry(name).or_insert_with(Vec::new).push(value); Ok(()) @@ -89,6 +101,7 @@ pub fn iter_preview(&self) -> impl Iterator { ('_', ""), ('#', ""), ('.', ""), + ('%', ""), ] .iter() .copied(), @@ -101,7 +114,7 @@ pub fn clear(&mut self) { pub fn remove(&mut self, name: char) -> bool { match name { - '_' | '#' | '.' => false, + '_' | '#' | '.' | '%' => false, _ => self.inner.remove(&name).is_some(), } }