So1aric 2025-06-15 13:08:52 +02:00 committed by GitHub
commit 46da686c44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 6 deletions

View File

@ -587,6 +587,7 @@ impl MappableCommand {
dap_disable_exceptions, "Disable exception breakpoints",
shell_pipe, "Pipe selections through shell command",
shell_pipe_to, "Pipe selections into shell command ignoring output",
shell_pipe_into_buffer, "Pipe selections into shell command and output in new buffer",
shell_insert_output, "Insert shell command output before selections",
shell_append_output, "Append shell command output after selections",
shell_keep_pipe, "Filter selections with shell predicate",
@ -6165,6 +6166,7 @@ enum ShellBehavior {
Ignore,
Insert,
Append,
OpenBuffer,
}
fn shell_pipe(cx: &mut Context) {
@ -6183,6 +6185,10 @@ fn shell_append_output(cx: &mut Context) {
shell_prompt(cx, "append-output:".into(), ShellBehavior::Append);
}
fn shell_pipe_into_buffer(cx: &mut Context) {
shell_prompt(cx, "pipe-into-buffer:".into(), ShellBehavior::OpenBuffer);
}
fn shell_keep_pipe(cx: &mut Context) {
ui::prompt(
cx,
@ -6301,7 +6307,7 @@ async fn shell_impl_async(
fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
let pipe = match behavior {
ShellBehavior::Replace | ShellBehavior::Ignore => true,
ShellBehavior::Replace | ShellBehavior::Ignore | ShellBehavior::OpenBuffer => true,
ShellBehavior::Insert | ShellBehavior::Append => false,
};
@ -6348,6 +6354,7 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
ShellBehavior::Replace => (range.from(), range.to(), range.len()),
ShellBehavior::Insert => (range.from(), range.from(), 0),
ShellBehavior::Append => (range.to(), range.to(), 0),
ShellBehavior::OpenBuffer => (0, 0, 0),
_ => (range.from(), range.from(), 0),
};
@ -6368,16 +6375,23 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
changes.push((from, to, Some(output)));
}
if behavior != &ShellBehavior::Ignore {
if behavior != &ShellBehavior::Ignore && behavior != &ShellBehavior::OpenBuffer {
let transaction = Transaction::change(doc.text(), changes.into_iter())
.with_selection(Selection::new(ranges, selection.primary_index()));
doc.apply(&transaction, view.id);
doc.append_changes_to_history(view);
}
// after replace cursor may be out of bounds, do this to
// make sure cursor is in view and update scroll as well
view.ensure_cursor_in_view(doc, config.scrolloff);
// after replace cursor may be out of bounds, do this to
// make sure cursor is in view and update scroll as well
view.ensure_cursor_in_view(doc, config.scrolloff);
} else if behavior == &ShellBehavior::OpenBuffer {
cx.editor.new_file(Action::Replace);
let (view, doc) = current!(cx.editor);
let transaction = Transaction::change(doc.text(), changes.into_iter());
doc.apply(&transaction, view.id);
doc.append_changes_to_history(view);
}
}
fn shell_prompt(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBehavior) {