From b045c3068b39826923128e991f7b26104fd02303 Mon Sep 17 00:00:00 2001 From: Gabor Pihaj Date: Sat, 6 Jul 2024 10:33:28 +0100 Subject: [PATCH] Add switch-replace command to be able to switch to an existing buffer --- helix-term/src/commands/engine/steel.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/helix-term/src/commands/engine/steel.rs b/helix-term/src/commands/engine/steel.rs index fa69a1d22..1ed9f5251 100644 --- a/helix-term/src/commands/engine/steel.rs +++ b/helix-term/src/commands/engine/steel.rs @@ -702,6 +702,7 @@ fn load_editor_api(engine: &mut Engine, generate_sources: bool) { // Arity 1 module.register_fn("editor->doc-id", cx_get_document_id); module.register_fn("editor-switch!", cx_switch); + module.register_fn("editor-switch-replace!", cx_switch_replace); module.register_fn("editor-set-focus!", |cx: &mut Context, view_id: ViewId| { cx.editor.focus(view_id) }); @@ -757,6 +758,7 @@ fn load_editor_api(engine: &mut Engine, generate_sources: bool) { template_function_arity_1("editor->doc-id"); template_function_arity_1("editor-switch!"); + template_function_arity_1("editor-switch-replace!"); template_function_arity_1("editor-set-focus!"); template_function_arity_1("editor-set-mode!"); template_function_arity_1("editor-doc-in-view?"); @@ -2266,6 +2268,10 @@ fn cx_switch(cx: &mut Context, doc_id: DocumentId) { cx.editor.switch(doc_id, Action::VerticalSplit) } +fn cx_switch_replace(cx: &mut Context, doc_id: DocumentId) { + cx.editor.switch(doc_id, Action::Replace) +} + fn cx_get_mode(cx: &mut Context) -> Mode { cx.editor.mode }