remove duplicated shell calls (#3465)

pull/4843/head
Bob 2 years ago committed by GitHub
parent 8102c3224f
commit 1db01caec7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4803,15 +4803,24 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
let mut ranges = SmallVec::with_capacity(selection.len()); let mut ranges = SmallVec::with_capacity(selection.len());
let text = doc.text().slice(..); let text = doc.text().slice(..);
let mut shell_output: Option<Tendril> = None;
let mut offset = 0isize; let mut offset = 0isize;
for range in selection.ranges() { for range in selection.ranges() {
let fragment = range.slice(text); let (output, success) = if let Some(output) = shell_output.as_ref() {
let (output, success) = match shell_impl(shell, cmd, pipe.then(|| fragment.into())) { (output.clone(), true)
Ok(result) => result, } else {
Err(err) => { let fragment = range.slice(text);
cx.editor.set_error(err.to_string()); match shell_impl(shell, cmd, pipe.then(|| fragment.into())) {
return; Ok(result) => {
if !pipe {
shell_output = Some(result.0.clone());
}
result
}
Err(err) => {
cx.editor.set_error(err.to_string());
return;
}
} }
}; };

Loading…
Cancel
Save