@@ -4342,80 +4342,77 @@ fn shell(cx: &mut Context, prompt: &str, behavior: ShellBehavior) {
4342 Some('|'),
4342 Some('|'),
4343 |_input: &str| Vec::new(),
4343 |_input: &str| Vec::new(),
4344 move |cx: &mut compositor::Context, input: &str, event: PromptEvent| {
4344 move |cx: &mut compositor::Context, input: &str, event: PromptEvent| {
4345+ if event != PromptEvent::Validate {
4345 let shell = &cx.editor.config.shell;
4348 let shell = &cx.editor.config.shell;
4346− if event == PromptEvent::Validate {
4347− let (view, doc) = current!(cx.editor);
4349+ let (view, doc) = current!(cx.editor);
4348− let selection = doc.selection(view.id);
4350+ let selection = doc.selection(view.id);
4350− let mut changes = Vec::with_capacity(selection.len());
4352+ let mut changes = Vec::with_capacity(selection.len());
4352− for range in selection.ranges() {
4354+ for range in selection.ranges() {
4354− match Command::new(&shell[0])
4355+ let mut process = match Command::new(&shell[0])
4355− .args(&shell[1..])
4356+ .args(&shell[1..])
4356− .arg(input)
4357+ .arg(input)
4357− .stdin(Stdio::piped())
4358+ .stdin(Stdio::piped())
4358− .stdout(Stdio::piped())
4359+ .stdout(Stdio::piped())
4359− .stderr(Stdio::piped())
4360+ .stderr(Stdio::piped())
4360− .spawn()
4361+ .spawn()
4362− Ok(p) => process = p,
4363+ Ok(process) => process,
4363− Err(e) => {
4364+ Err(e) => {
4364− log::error!("Failed to start shell: {}", e);
4365+ log::error!("Failed to start shell: {}", e);
4365− cx.editor.set_error("Failed to start shell".to_owned());
4366+ cx.editor.set_error("Failed to start shell".to_owned());
4366− return;
4367+ return;
4370− let stdin = process.stdin.as_mut().unwrap();
4371− let fragment = range.fragment(doc.text().slice(..));
4372− stdin.write_all(fragment.as_bytes()).unwrap();
4371+ let stdin = process.stdin.as_mut().unwrap();
4372+ let fragment = range.fragment(doc.text().slice(..));
4373+ stdin.write_all(fragment.as_bytes()).unwrap();
4375+ let output = process.wait_with_output().unwrap();
4375− let output = process.wait_with_output().unwrap();
4376− if behavior != ShellBehavior::Filter {
4377+ if behavior != ShellBehavior::Filter {
4377− if !output.status.success() {
4378+ if !output.status.success() {
4378− let stderr = output.stderr;
4379− if !stderr.is_empty() {
4379+ if !output.stderr.is_empty() {
4380− log::error!("Shell error: {}", String::from_utf8_lossy(&stderr));
4380+ log::error!("Shell error: {}", String::from_utf8_lossy(&output.stderr));
4382− cx.editor.set_error("Command failed".to_owned());
4385− let stdout = output.stdout;
4387− match Tendril::try_from_byte_slice(&stdout) {
4388− Ok(t) => tendril = t,
4391− .set_error("Process did not output valid UTF-8".to_owned());
4382+ cx.editor.set_error("Command failed".to_owned());
4392− return;
4383+ return;
4395− let (from, to) = match behavior {
4396− ShellBehavior::Replace => (range.from(), range.to()),
4397− ShellBehavior::Insert => (range.from(), range.from()),
4398− ShellBehavior::Append => (range.to(), range.to()),
4399− _ => (range.from(), range.from()),
4401− changes.push((from, to, Some(tendril)));
4403− // if the process exits successfully, keep the selection, otherwise delete it.
4404− let keep = output.status.success();
4407− if keep { range.from() } else { range.to() },
4385+ let tendril = match Tendril::try_from_byte_slice(&output.stdout) {
4386+ Ok(tendril) => tendril,
4389+ .set_error("Process did not output valid UTF-8".to_owned());
4393+ let (from, to) = match behavior {
4394+ ShellBehavior::Replace => (range.from(), range.to()),
4395+ ShellBehavior::Insert => (range.from(), range.from()),
4396+ ShellBehavior::Append => (range.to(), range.to()),
4397+ _ => (range.from(), range.from()),
4399+ changes.push((from, to, Some(tendril)));
4401+ // if the process exits successfully, keep the selection, otherwise delete it.
4402+ let keep = output.status.success();
4405+ if keep { range.from() } else { range.to() },
4413− let transaction = Transaction::change(doc.text(), changes.into_iter());
4411+ let transaction = Transaction::change(doc.text(), changes.into_iter());
4415− if behavior != ShellBehavior::Ignore {
4413+ if behavior != ShellBehavior::Ignore {
4416− doc.apply(&transaction, view.id);
4414+ doc.apply(&transaction, view.id);
4417− doc.append_changes_to_history(view.id);
4415+ doc.append_changes_to_history(view.id);