on master help sign in
remove duplicated shell calls (#3465)
1db01caBob
helix-term/src/commands.rs+16−7
@@ -4803,15 +4803,24 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
4803 let mut ranges = SmallVec::with_capacity(selection.len());
4803 let mut ranges = SmallVec::with_capacity(selection.len());
4804 let text = doc.text().slice(..);
4804 let text = doc.text().slice(..);
4805
4805
4806+ let mut shell_output: Option<Tendril> = None;
4806 let mut offset = 0isize;
4807 let mut offset = 0isize;
4807−
4808 for range in selection.ranges() {
4808 for range in selection.ranges() {
4809+ let (output, success) = if let Some(output) = shell_output.as_ref() {
4810+ (output.clone(), true)
4811+ } else {
4809− let fragment = range.slice(text);
4812+ let fragment = range.slice(text);
4810− let (output, success) = match shell_impl(shell, cmd, pipe.then(|| fragment.into())) {
4813+ match shell_impl(shell, cmd, pipe.then(|| fragment.into())) {
4811− Ok(result) => result,
4814+ Ok(result) => {
4815+ if !pipe {
4816+ shell_output = Some(result.0.clone());
4817+ }
4818+ result
4819+ }
4812− Err(err) => {
4820+ Err(err) => {
4813− cx.editor.set_error(err.to_string());
4821+ cx.editor.set_error(err.to_string());
4814− return;
4822+ return;
4823+ }
4815 }
4824 }
4816 };
4825 };
4817
4826