From 332c3e5b3d53a1c95fe3f6e41331675ce1d21d18 Mon Sep 17 00:00:00 2001 From: Rolo Date: Fri, 14 Jun 2024 01:17:27 -0700 Subject: [PATCH] refactor(commands): trim end of `pipe`-like output --- helix-term/src/commands.rs | 4 ++-- helix-term/tests/test/commands.rs | 29 ++++++++++------------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 5fc832351df34..f2c5e969ae5d6 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -5755,7 +5755,7 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) { let mut offset = 0isize; for range in selection.ranges() { let output = if let Some(output) = shell_output.as_ref() { - output.clone() + Tendril::from(output.trim_end()) } else { let fragment = range.slice(text); match shell_impl(shell, cmd, pipe.then(|| fragment.into())) { @@ -5763,7 +5763,7 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) { if !pipe { shell_output = Some(result.clone()); } - result + Tendril::from(result.trim_end()) } Err(err) => { cx.editor.set_error(err.to_string()); diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 7f41a2219acbf..9f196827faf3e 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -209,13 +209,10 @@ async fn test_multi_selection_shell_commands() -> anyhow::Result<()> { "}, "|echo foo", indoc! {"\ - #[|foo\n]# - - #(|foo\n)# - - #(|foo\n)# - - "}, + #[|foo]# + #(|foo)# + #(|foo)#" + }, )) .await?; @@ -228,12 +225,9 @@ async fn test_multi_selection_shell_commands() -> anyhow::Result<()> { "}, "!echo foo", indoc! {"\ - #[|foo\n]# - lorem - #(|foo\n)# - ipsum - #(|foo\n)# - dolor + #[|foo]#lorem + #(|foo)#ipsum + #(|foo)#dolor "}, )) .await?; @@ -247,12 +241,9 @@ async fn test_multi_selection_shell_commands() -> anyhow::Result<()> { "}, "echo foo", indoc! {"\ - lorem#[|foo\n]# - - ipsum#(|foo\n)# - - dolor#(|foo\n)# - + lorem#[|foo]# + ipsum#(|foo)# + dolor#(|foo)# "}, )) .await?;