Skip to content

Commit

Permalink
remove duplicated shell calls (helix-editor#3465)
Browse files Browse the repository at this point in the history
  • Loading branch information
QiBaobin authored and Shekhinah Memmel committed Dec 11, 2022
1 parent 7e7f564 commit bae460a
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4843,15 +4843,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;
}
}
};

Expand Down

0 comments on commit bae460a

Please sign in to comment.