aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorBob2022-11-22 01:55:46 +0000
committerGitHub2022-11-22 01:55:46 +0000
commit1db01caec7c91e270a23fd4f85955bb235ffbcb7 (patch)
tree61568eb8eaf38ebaf3bc8bec23ca185220e69f1d /helix-term/src
parent8102c3224f8cbf4a8e679377fef6ea98ed337cba (diff)
remove duplicated shell calls (#3465)
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs23
1 files changed, 16 insertions, 7 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index f384612b..5b44775b 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -4803,15 +4803,24 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
let mut ranges = SmallVec::with_capacity(selection.len());
let text = doc.text().slice(..);
+ let mut shell_output: Option<Tendril> = None;
let mut offset = 0isize;
-
for range in selection.ranges() {
- let fragment = range.slice(text);
- let (output, success) = match shell_impl(shell, cmd, pipe.then(|| fragment.into())) {
- Ok(result) => result,
- Err(err) => {
- cx.editor.set_error(err.to_string());
- return;
+ let (output, success) = if let Some(output) = shell_output.as_ref() {
+ (output.clone(), true)
+ } else {
+ let fragment = range.slice(text);
+ match shell_impl(shell, cmd, pipe.then(|| fragment.into())) {
+ Ok(result) => {
+ if !pipe {
+ shell_output = Some(result.0.clone());
+ }
+ result
+ }
+ Err(err) => {
+ cx.editor.set_error(err.to_string());
+ return;
+ }
}
};