From 9120f55892310a31b4dd751c8ace9f4b3a03af67 Mon Sep 17 00:00:00 2001 From: kirawi <67773714+kirawi@users.noreply.github.com> Date: Tue, 19 Mar 2024 11:12:17 -0400 Subject: [PATCH] add register completion --- helix-term/src/commands/typed.rs | 20 ++++++++++---------- helix-term/src/ui/mod.rs | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 593837e22efd..0dfcdb6e9bee 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2423,6 +2423,14 @@ fn yank_diagnostic( return Ok(()); } + let reg = match args.first() { + Some(s) => { + ensure!(s.chars().count() == 1, format!("Invalid register {s}")); + s.chars().next().unwrap() + } + None => '+', + }; + let (view, doc) = current_ref!(cx.editor); let primary = doc.selection(view.id).primary(); @@ -2438,14 +2446,6 @@ fn yank_diagnostic( bail!("No diagnostics under primary selection"); } - let reg = match args.get(0) { - Some(s) => { - ensure!(s.chars().count() == 1, format!("Invalid register {s}")); - s.chars().next().unwrap() - } - None => '+', - }; - cx.editor.registers.write(reg, diag)?; cx.editor.set_status(format!( "Yanked {n} diagnostic{} to register {reg}", @@ -3045,7 +3045,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ aliases: &[], doc: "Clear given register. If no argument is provided, clear all registers.", fun: clear_register, - signature: CommandSignature::none(), + signature: CommandSignature::all(completers::register), }, TypableCommand { name: "redraw", @@ -3066,7 +3066,7 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ aliases: &[], doc: "Yank diagnostic(s) under primary cursor to register, or clipboard by default", fun: yank_diagnostic, - signature: CommandSignature::none(), + signature: CommandSignature::all(completers::register), }, ]; diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index a4b148af3442..b5969818cf56 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -509,4 +509,18 @@ pub mod completers { files } } + + pub fn register(editor: &Editor, input: &str) -> Vec { + let iter = editor + .registers + .iter_preview() + // Exclude special registers that shouldn't be written to + .filter(|(ch, _)| !matches!(ch, '%' | '#' | '.')) + .map(|(ch, _)| ch.to_string()); + + fuzzy_match(input, iter, false) + .into_iter() + .map(|(name, _)| ((0..), name.into())) + .collect() + } }