mirror of https://github.com/helix-editor/helix
Implement editor-switch-action instead of hardcoded replace
parent
b045c3068b
commit
a06824308b
|
@ -702,7 +702,6 @@ fn load_editor_api(engine: &mut Engine, generate_sources: bool) {
|
||||||
// Arity 1
|
// Arity 1
|
||||||
module.register_fn("editor->doc-id", cx_get_document_id);
|
module.register_fn("editor->doc-id", cx_get_document_id);
|
||||||
module.register_fn("editor-switch!", cx_switch);
|
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| {
|
module.register_fn("editor-set-focus!", |cx: &mut Context, view_id: ViewId| {
|
||||||
cx.editor.focus(view_id)
|
cx.editor.focus(view_id)
|
||||||
});
|
});
|
||||||
|
@ -711,6 +710,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::<
|
||||||
_,
|
_,
|
||||||
|
@ -758,7 +760,6 @@ fn load_editor_api(engine: &mut Engine, generate_sources: bool) {
|
||||||
|
|
||||||
template_function_arity_1("editor->doc-id");
|
template_function_arity_1("editor->doc-id");
|
||||||
template_function_arity_1("editor-switch!");
|
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-focus!");
|
||||||
template_function_arity_1("editor-set-mode!");
|
template_function_arity_1("editor-set-mode!");
|
||||||
template_function_arity_1("editor-doc-in-view?");
|
template_function_arity_1("editor-doc-in-view?");
|
||||||
|
@ -766,6 +767,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() {
|
||||||
|
@ -2268,8 +2282,8 @@ 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_replace(cx: &mut Context, doc_id: DocumentId) {
|
fn cx_switch_action(cx: &mut Context, doc_id: DocumentId, action: Action) {
|
||||||
cx.editor.switch(doc_id, Action::Replace)
|
cx.editor.switch(doc_id, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cx_get_mode(cx: &mut Context) -> Mode {
|
fn cx_get_mode(cx: &mut Context) -> 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…
Reference in New Issue