mirror of https://github.com/helix-editor/helix
Merge 962a27cab7
into 205e7ece70
commit
46da686c44
|
@ -587,6 +587,7 @@ impl MappableCommand {
|
||||||
dap_disable_exceptions, "Disable exception breakpoints",
|
dap_disable_exceptions, "Disable exception breakpoints",
|
||||||
shell_pipe, "Pipe selections through shell command",
|
shell_pipe, "Pipe selections through shell command",
|
||||||
shell_pipe_to, "Pipe selections into shell command ignoring output",
|
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_insert_output, "Insert shell command output before selections",
|
||||||
shell_append_output, "Append shell command output after selections",
|
shell_append_output, "Append shell command output after selections",
|
||||||
shell_keep_pipe, "Filter selections with shell predicate",
|
shell_keep_pipe, "Filter selections with shell predicate",
|
||||||
|
@ -6165,6 +6166,7 @@ enum ShellBehavior {
|
||||||
Ignore,
|
Ignore,
|
||||||
Insert,
|
Insert,
|
||||||
Append,
|
Append,
|
||||||
|
OpenBuffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shell_pipe(cx: &mut Context) {
|
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);
|
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) {
|
fn shell_keep_pipe(cx: &mut Context) {
|
||||||
ui::prompt(
|
ui::prompt(
|
||||||
cx,
|
cx,
|
||||||
|
@ -6301,7 +6307,7 @@ async fn shell_impl_async(
|
||||||
|
|
||||||
fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
|
fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
|
||||||
let pipe = match behavior {
|
let pipe = match behavior {
|
||||||
ShellBehavior::Replace | ShellBehavior::Ignore => true,
|
ShellBehavior::Replace | ShellBehavior::Ignore | ShellBehavior::OpenBuffer => true,
|
||||||
ShellBehavior::Insert | ShellBehavior::Append => false,
|
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::Replace => (range.from(), range.to(), range.len()),
|
||||||
ShellBehavior::Insert => (range.from(), range.from(), 0),
|
ShellBehavior::Insert => (range.from(), range.from(), 0),
|
||||||
ShellBehavior::Append => (range.to(), range.to(), 0),
|
ShellBehavior::Append => (range.to(), range.to(), 0),
|
||||||
|
ShellBehavior::OpenBuffer => (0, 0, 0),
|
||||||
_ => (range.from(), range.from(), 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)));
|
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())
|
let transaction = Transaction::change(doc.text(), changes.into_iter())
|
||||||
.with_selection(Selection::new(ranges, selection.primary_index()));
|
.with_selection(Selection::new(ranges, selection.primary_index()));
|
||||||
doc.apply(&transaction, view.id);
|
doc.apply(&transaction, view.id);
|
||||||
doc.append_changes_to_history(view);
|
doc.append_changes_to_history(view);
|
||||||
}
|
|
||||||
|
|
||||||
// after replace cursor may be out of bounds, do this to
|
// after replace cursor may be out of bounds, do this to
|
||||||
// make sure cursor is in view and update scroll as well
|
// make sure cursor is in view and update scroll as well
|
||||||
view.ensure_cursor_in_view(doc, config.scrolloff);
|
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) {
|
fn shell_prompt(cx: &mut Context, prompt: Cow<'static, str>, behavior: ShellBehavior) {
|
||||||
|
|
Loading…
Reference in New Issue