From 27aea00f28d4814bfd19a13d6c736a58e03f76a0 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:43:06 +0000 Subject: [PATCH] feat: add register / for parent path --- helix-view/src/register.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/helix-view/src/register.rs b/helix-view/src/register.rs index 3a2e1b7cc..cdb7a6057 100644 --- a/helix-view/src/register.rs +++ b/helix-view/src/register.rs @@ -63,6 +63,18 @@ impl Registers { let path = doc!(editor).display_name(); Some(RegisterValues::new(iter::once(path))) } + '/' => { + let relative_path = match doc!(editor).path() { + Some(path) => path, + None => return Some(RegisterValues::new(iter::empty())), + }; + let parent = match relative_path.parent() { + Some(path) => path, + None => return Some(RegisterValues::new(iter::empty())), + }; + let parent = parent.display().to_string(); + Some(RegisterValues::new(iter::once(parent.into()))) + } '*' | '+' => Some(read_from_clipboard( self.clipboard_provider.as_ref(), self.inner.get(&name), @@ -82,7 +94,9 @@ impl Registers { pub fn write(&mut self, name: char, mut values: Vec) -> Result<()> { match name { '_' => Ok(()), - '#' | '.' | '%' => Err(anyhow::anyhow!("Register {name} does not support writing")), + '#' | '.' | '%' | '/' => { + Err(anyhow::anyhow!("Register {name} does not support writing")) + } '*' | '+' => { self.clipboard_provider.set_contents( values.join(NATIVE_LINE_ENDING.as_str()), @@ -107,7 +121,9 @@ impl Registers { pub fn push(&mut self, name: char, mut value: String) -> Result<()> { match name { '_' => Ok(()), - '#' | '.' | '%' => Err(anyhow::anyhow!("Register {name} does not support pushing")), + '#' | '.' | '%' | '/' => { + Err(anyhow::anyhow!("Register {name} does not support pushing")) + } '*' | '+' => { let clipboard_type = match name { '+' => ClipboardType::Clipboard, @@ -164,6 +180,7 @@ impl Registers { ('#', ""), ('.', ""), ('%', ""), + ('/', ""), ('+', ""), ('*', ""), ]