Merge pull request #2 from voidcontext/switch-replace

Add editor-switch-action! command to be able to switch to an existing buffer
pull/8675/merge^2
Matthew Paras 5 months ago committed by GitHub
commit d1da0f5b37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -692,6 +692,12 @@ fn load_configuration_api(engine: &mut Engine, generate_sources: bool) {
fn load_editor_api(engine: &mut Engine, generate_sources: bool) { fn load_editor_api(engine: &mut Engine, generate_sources: bool) {
let mut module = BuiltInModule::new("helix/core/editor"); let mut module = BuiltInModule::new("helix/core/editor");
// Types
module.register_fn("Action/Load", || Action::Load);
module.register_fn("Action/Replace", || Action::Replace);
module.register_fn("Action/HorizontalSplit", || Action::HorizontalSplit);
module.register_fn("Action/VerticalSplit", || Action::VerticalSplit);
// Arity 0 // Arity 0
module.register_fn("editor-focus", cx_current_focus); module.register_fn("editor-focus", cx_current_focus);
module.register_fn("editor-mode", cx_get_mode); module.register_fn("editor-mode", cx_get_mode);
@ -710,6 +716,9 @@ fn load_editor_api(engine: &mut Engine, generate_sources: bool) {
module.register_fn("set-scratch-buffer-name!", set_scratch_buffer_name); module.register_fn("set-scratch-buffer-name!", set_scratch_buffer_name);
module.register_fn("editor-doc-exists?", cx_document_exists); module.register_fn("editor-doc-exists?", cx_document_exists);
// Arity 2
module.register_fn("editor-switch-action!", cx_switch_action);
// Arity 1 // Arity 1
RegisterFn::< RegisterFn::<
_, _,
@ -727,6 +736,22 @@ fn load_editor_api(engine: &mut Engine, generate_sources: bool) {
let mut builtin_editor_command_module = let mut builtin_editor_command_module =
"(require-builtin helix/core/editor as helix.)".to_string(); "(require-builtin helix/core/editor as helix.)".to_string();
let mut template_function_type_constructor = |name: &str| {
builtin_editor_command_module.push_str(&format!(
r#"
(provide {})
(define ({})
(helix.{}))
"#,
name, name, name
));
};
template_function_type_constructor("Action/Load");
template_function_type_constructor("Action/Replace");
template_function_type_constructor("Action/HorizontalSplit");
template_function_type_constructor("Action/VerticalSplit");
let mut template_function_arity_0 = |name: &str| { let mut template_function_arity_0 = |name: &str| {
builtin_editor_command_module.push_str(&format!( builtin_editor_command_module.push_str(&format!(
r#" r#"
@ -764,6 +789,19 @@ fn load_editor_api(engine: &mut Engine, generate_sources: bool) {
template_function_arity_1("editor-doc-exists?"); template_function_arity_1("editor-doc-exists?");
template_function_arity_1("editor->get-document"); template_function_arity_1("editor->get-document");
let mut template_function_arity_2 = |name: &str| {
builtin_editor_command_module.push_str(&format!(
r#"
(provide {})
(define ({} arg1 arg2)
(helix.{} *helix.cx* arg1 arg2))
"#,
name, name, name
));
};
template_function_arity_2("editor-switch-action!");
let mut target_directory = helix_runtime_search_path(); let mut target_directory = helix_runtime_search_path();
if !target_directory.exists() { if !target_directory.exists() {
@ -2266,6 +2304,10 @@ fn cx_switch(cx: &mut Context, doc_id: DocumentId) {
cx.editor.switch(doc_id, Action::VerticalSplit) cx.editor.switch(doc_id, Action::VerticalSplit)
} }
fn cx_switch_action(cx: &mut Context, doc_id: DocumentId, action: Action) {
cx.editor.switch(doc_id, action)
}
fn cx_get_mode(cx: &mut Context) -> Mode { fn cx_get_mode(cx: &mut Context) -> Mode {
cx.editor.mode cx.editor.mode
} }

@ -15,9 +15,7 @@ mod steel_implementations {
use crate::{ use crate::{
document::Mode, document::Mode,
editor::{ editor::{
BufferLine, CursorShapeConfig, FilePickerConfig, GutterConfig, IndentGuidesConfig, Action, BufferLine, CursorShapeConfig, FilePickerConfig, GutterConfig, IndentGuidesConfig, LineEndingConfig, LineNumber, LspConfig, SearchConfig, SmartTabConfig, StatusLineConfig, TerminalConfig, WhitespaceConfig
LineEndingConfig, LineNumber, LspConfig, SearchConfig, SmartTabConfig,
StatusLineConfig, TerminalConfig, WhitespaceConfig,
}, },
graphics::{Color, Rect, Style, UnderlineStyle}, graphics::{Color, Rect, Style, UnderlineStyle},
input::Event, input::Event,
@ -56,6 +54,8 @@ mod steel_implementations {
impl Custom for ViewId {} impl Custom for ViewId {}
impl CustomReference for Document {} impl CustomReference for Document {}
impl Custom for Action {}
impl Custom for FilePickerConfig {} impl Custom for FilePickerConfig {}
impl Custom for StatusLineConfig {} impl Custom for StatusLineConfig {}
impl Custom for SearchConfig {} impl Custom for SearchConfig {}

Loading…
Cancel
Save