diff --git a/helix-core/src/register.rs b/helix-core/src/register.rs index 52eb6e3e72bf3..6a4719ba43dbc 100644 --- a/helix-core/src/register.rs +++ b/helix-core/src/register.rs @@ -57,6 +57,10 @@ impl Registers { } } + pub fn clear(&mut self, name: char) { + self.inner.remove(&name); + } + pub fn push(&mut self, name: char, value: String) { if name != '_' { if let Some(r) = self.inner.get_mut(&name) { diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 5b3ce68ec85c9..e2d5bc9d2ea74 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4418,6 +4418,7 @@ fn wonly(cx: &mut Context) { } fn select_register(cx: &mut Context) { + cx.editor.update_registers(); cx.editor.autoinfo = Some(Info::from_registers(&cx.editor.registers)); cx.on_next_key(move |cx, event| { if let Some(ch) = event.char() { @@ -4428,6 +4429,7 @@ fn select_register(cx: &mut Context) { } fn insert_register(cx: &mut Context) { + cx.editor.update_registers(); cx.editor.autoinfo = Some(Info::from_registers(&cx.editor.registers)); cx.on_next_key(move |cx, event| { if let Some(ch) = event.char() { diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index 5fb6745a90e53..177e4db848b26 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -592,6 +592,7 @@ impl Component for Prompt { } ctrl!('q') => self.exit_selection(), ctrl!('r') => { + cx.editor.update_registers(); self.completion = cx .editor .registers diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 4a44a00cbce02..022f76d065c34 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1469,6 +1469,17 @@ impl Editor { doc.restore_cursor = false; } } + + /// Update read-only registers. + pub fn update_registers(&mut self) { + let doc = doc!(self); + if let Some(path) = doc.relative_path() { + self.registers + .write('%', vec![path.to_string_lossy().to_string()]); + } else { + self.registers.clear('%'); + } + } } fn try_restore_indent(doc: &mut Document, view: &mut View) {