mirror of https://github.com/helix-editor/helix
feat(term): add `shell_pipe_into_buffer` command.
parent
f6878f62f7
commit
e8b4be7aef
|
@ -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",
|
||||
|
@ -6148,6 +6149,7 @@ enum ShellBehavior {
|
|||
Ignore,
|
||||
Insert,
|
||||
Append,
|
||||
OpenBuffer,
|
||||
}
|
||||
|
||||
fn shell_pipe(cx: &mut Context) {
|
||||
|
@ -6166,6 +6168,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, "open-buffer:".into(), ShellBehavior::OpenBuffer);
|
||||
}
|
||||
|
||||
fn shell_keep_pipe(cx: &mut Context) {
|
||||
ui::prompt(
|
||||
cx,
|
||||
|
@ -6285,7 +6291,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::Insert | ShellBehavior::Append => false,
|
||||
ShellBehavior::Insert | ShellBehavior::Append | ShellBehavior::OpenBuffer => false,
|
||||
};
|
||||
|
||||
let config = cx.editor.config();
|
||||
|
@ -6331,6 +6337,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),
|
||||
};
|
||||
|
||||
|
@ -6351,16 +6358,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) {
|
||||
|
|
Loading…
Reference in New Issue