From 65748bfd7ab1cca7f47fb4f1133588d27b958ba7 Mon Sep 17 00:00:00 2001 From: kirawi <67773714+kirawi@users.noreply.github.com> Date: Thu, 15 Feb 2024 21:05:34 -0500 Subject: [PATCH] wip --- helix-term/src/commands.rs | 27 +++++++++++++++++++++++++++ helix-view/src/register.rs | 4 +++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index d44f477b73764..d2004012fffbf 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -388,6 +388,7 @@ impl MappableCommand { yank_main_selection_to_clipboard, "Yank main selection to clipboard", yank_joined_to_primary_clipboard, "Join and yank selections to primary clipboard", yank_main_selection_to_primary_clipboard, "Yank main selection to primary clipboard", + yank_diagnostic, "Yank diagnostic to register or clipboard by default", replace_with_yanked, "Replace with yanked text", replace_selections_with_clipboard, "Replace selections by clipboard content", replace_selections_with_primary_clipboard, "Replace selections by primary clipboard", @@ -5519,6 +5520,32 @@ fn increment_impl(cx: &mut Context, increment_direction: IncrementDirection) { } } +fn yank_diagnostic(cx: &mut Context) { + let (view, doc) = current_ref!(cx.editor); + let primary = doc.selection(view.id).primary(); + + let default_sep = doc.line_ending.as_str(); + let diag = doc + .diagnostics() + .iter() + .filter(|d| primary.overlaps(&helix_core::Range::new(d.range.start, d.range.end))) + .map(|d| d.message.clone()) + .fold(String::new(), |mut acc, fragment| { + if !acc.is_empty() { + acc.push_str(default_sep); + } + acc.push_str(&fragment); + acc + }); + let reg = cx.register.unwrap_or('+'); + match cx.editor.registers.write(reg, vec![diag]) { + Ok(_) => cx + .editor + .set_status(format!("Yanked diagnostic(s) to register {reg}")), + Err(err) => cx.editor.set_error(err.to_string()), + } +} + fn record_macro(cx: &mut Context) { if let Some((reg, mut keys)) = cx.editor.macro_recording.take() { // Remove the keypress which ends the recording diff --git a/helix-view/src/register.rs b/helix-view/src/register.rs index 5592c6afd7811..1e66801501844 100644 --- a/helix-view/src/register.rs +++ b/helix-view/src/register.rs @@ -233,7 +233,9 @@ fn read_from_clipboard<'a>( // If we're pasting the same values that we just yanked, re-use // the saved values. This allows pasting multiple selections // even when yanked to a clipboard. - let Some(values) = saved_values else { return RegisterValues::new(iter::once(contents.into())) }; + let Some(values) = saved_values else { + return RegisterValues::new(iter::once(contents.into())); + }; if contents_are_saved(values, &contents) { RegisterValues::new(values.iter().map(Cow::from).rev())