Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Register NewFile and NewFileInDirection from Editor
Antonio Scandurrafaa896343b4d
diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rsindex ffc32dc83fe..faa6e5f5cae 100644--- a/crates/editor2/src/editor.rs+++ b/crates/editor2/src/editor.rs@@ -407,133 +407,17 @@ pub fn init_settings(cx: &mut AppContext) {pub fn init(cx: &mut AppContext) {init_settings(cx);- // cx.register_action_type(Editor::new_file);- // cx.register_action_type(Editor::new_file_in_direction);- // cx.register_action_type(Editor::cancel);- // cx.register_action_type(Editor::newline);- // cx.register_action_type(Editor::newline_above);- // cx.register_action_type(Editor::newline_below);- // cx.register_action_type(Editor::backspace);- // cx.register_action_type(Editor::delete);- // cx.register_action_type(Editor::tab);- // cx.register_action_type(Editor::tab_prev);- // cx.register_action_type(Editor::indent);- // cx.register_action_type(Editor::outdent);- // cx.register_action_type(Editor::delete_line);- // cx.register_action_type(Editor::join_lines);- // cx.register_action_type(Editor::sort_lines_case_sensitive);- // cx.register_action_type(Editor::sort_lines_case_insensitive);- // cx.register_action_type(Editor::reverse_lines);- // cx.register_action_type(Editor::shuffle_lines);- // cx.register_action_type(Editor::convert_to_upper_case);- // cx.register_action_type(Editor::convert_to_lower_case);- // cx.register_action_type(Editor::convert_to_title_case);- // cx.register_action_type(Editor::convert_to_snake_case);- // cx.register_action_type(Editor::convert_to_kebab_case);- // cx.register_action_type(Editor::convert_to_upper_camel_case);- // cx.register_action_type(Editor::convert_to_lower_camel_case);- // cx.register_action_type(Editor::delete_to_previous_word_start);- // cx.register_action_type(Editor::delete_to_previous_subword_start);- // cx.register_action_type(Editor::delete_to_next_word_end);- // cx.register_action_type(Editor::delete_to_next_subword_end);- // cx.register_action_type(Editor::delete_to_beginning_of_line);- // cx.register_action_type(Editor::delete_to_end_of_line);- // cx.register_action_type(Editor::cut_to_end_of_line);- // cx.register_action_type(Editor::duplicate_line);- // cx.register_action_type(Editor::move_line_up);- // cx.register_action_type(Editor::move_line_down);- // cx.register_action_type(Editor::transpose);- // cx.register_action_type(Editor::cut);- // cx.register_action_type(Editor::copy);- // cx.register_action_type(Editor::paste);- // cx.register_action_type(Editor::undo);- // cx.register_action_type(Editor::redo);- // cx.register_action_type(Editor::move_page_up);- // cx.register_action_type::<MoveDown>();- // cx.register_action_type(Editor::move_page_down);- // cx.register_action_type(Editor::next_screen);- // cx.register_action_type::<MoveLeft>();- // cx.register_action_type::<MoveRight>();- // cx.register_action_type(Editor::move_to_previous_word_start);- // cx.register_action_type(Editor::move_to_previous_subword_start);- // cx.register_action_type(Editor::move_to_next_word_end);- // cx.register_action_type(Editor::move_to_next_subword_end);- // cx.register_action_type(Editor::move_to_beginning_of_line);- // cx.register_action_type(Editor::move_to_end_of_line);- // cx.register_action_type(Editor::move_to_start_of_paragraph);- // cx.register_action_type(Editor::move_to_end_of_paragraph);- // cx.register_action_type(Editor::move_to_beginning);- // cx.register_action_type(Editor::move_to_end);- // cx.register_action_type(Editor::select_up);- // cx.register_action_type(Editor::select_down);- // cx.register_action_type(Editor::select_left);- // cx.register_action_type(Editor::select_right);- // cx.register_action_type(Editor::select_to_previous_word_start);- // cx.register_action_type(Editor::select_to_previous_subword_start);- // cx.register_action_type(Editor::select_to_next_word_end);- // cx.register_action_type(Editor::select_to_next_subword_end);- // cx.register_action_type(Editor::select_to_beginning_of_line);- // cx.register_action_type(Editor::select_to_end_of_line);- // cx.register_action_type(Editor::select_to_start_of_paragraph);- // cx.register_action_type(Editor::select_to_end_of_paragraph);- // cx.register_action_type(Editor::select_to_beginning);- // cx.register_action_type(Editor::select_to_end);- // cx.register_action_type(Editor::select_all);- // cx.register_action_type(Editor::select_all_matches);- // cx.register_action_type(Editor::select_line);- // cx.register_action_type(Editor::split_selection_into_lines);- // cx.register_action_type(Editor::add_selection_above);- // cx.register_action_type(Editor::add_selection_below);- // cx.register_action_type(Editor::select_next);- // cx.register_action_type(Editor::select_previous);- // cx.register_action_type(Editor::toggle_comments);- // cx.register_action_type(Editor::select_larger_syntax_node);- // cx.register_action_type(Editor::select_smaller_syntax_node);- // cx.register_action_type(Editor::move_to_enclosing_bracket);- // cx.register_action_type(Editor::undo_selection);- // cx.register_action_type(Editor::redo_selection);- // cx.register_action_type(Editor::go_to_diagnostic);- // cx.register_action_type(Editor::go_to_prev_diagnostic);- // cx.register_action_type(Editor::go_to_hunk);- // cx.register_action_type(Editor::go_to_prev_hunk);- // cx.register_action_type(Editor::go_to_definition);- // cx.register_action_type(Editor::go_to_definition_split);- // cx.register_action_type(Editor::go_to_type_definition);- // cx.register_action_type(Editor::go_to_type_definition_split);- // cx.register_action_type(Editor::fold);- // cx.register_action_type(Editor::fold_at);- // cx.register_action_type(Editor::unfold_lines);- // cx.register_action_type(Editor::unfold_at);- // cx.register_action_type(Editor::gutter_hover);- // cx.register_action_type(Editor::fold_selected_ranges);- // cx.register_action_type(Editor::show_completions);- // cx.register_action_type(Editor::toggle_code_actions);- // cx.register_action_type(Editor::open_excerpts);- // cx.register_action_type(Editor::toggle_soft_wrap);- // cx.register_action_type(Editor::toggle_inlay_hints);- // cx.register_action_type(Editor::reveal_in_finder);- // cx.register_action_type(Editor::copy_path);- // cx.register_action_type(Editor::copy_relative_path);- // cx.register_action_type(Editor::copy_highlight_json);- // cx.add_async_action(Editor::format);- // cx.register_action_type(Editor::restart_language_server);- // cx.register_action_type(Editor::show_character_palette);- // cx.add_async_action(Editor::confirm_completion);- // cx.add_async_action(Editor::confirm_code_action);- // cx.add_async_action(Editor::rename);- // cx.add_async_action(Editor::confirm_rename);- // cx.add_async_action(Editor::find_all_references);- // cx.register_action_type(Editor::next_copilot_suggestion);- // cx.register_action_type(Editor::previous_copilot_suggestion);- // cx.register_action_type(Editor::copilot_suggest);- // cx.register_action_type(Editor::context_menu_first);- // cx.register_action_type(Editor::context_menu_prev);- // cx.register_action_type(Editor::context_menu_next);- // cx.register_action_type(Editor::context_menu_last);workspace::register_project_item::<Editor>(cx);workspace::register_followable_item::<Editor>(cx);workspace::register_deserializable_item::<Editor>(cx);+ cx.observe_new_views(+ |workspace: &mut Workspace, cx: &mut ViewContext<Workspace>| {+ workspace.register_action(Editor::new_file);+ workspace.register_action(Editor::new_file_in_direction);+ },+ )+ .detach();}trait InvalidationRegion {@@ -1990,25 +1874,25 @@ impl Editor {}}- // pub fn new_file_in_direction(- // workspace: &mut Workspace,- // action: &workspace::NewFileInDirection,- // cx: &mut ViewContext<Workspace>,- // ) {- // let project = workspace.project().clone();- // if project.read(cx).is_remote() {- // cx.propagate();- // } else if let Some(buffer) = project- // .update(cx, |project, cx| project.create_buffer("", None, cx))- // .log_err()- // {- // workspace.split_item(- // action.0,- // Box::new(cx.add_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx))),- // cx,- // );- // }- // }+ pub fn new_file_in_direction(+ workspace: &mut Workspace,+ action: &workspace::NewFileInDirection,+ cx: &mut ViewContext<Workspace>,+ ) {+ let project = workspace.project().clone();+ if project.read(cx).is_remote() {+ cx.propagate();+ } else if let Some(buffer) = project+ .update(cx, |project, cx| project.create_buffer("", None, cx))+ .log_err()+ {+ workspace.split_item(+ action.0,+ Box::new(cx.build_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx))),+ cx,+ );+ }+ }pub fn replica_id(&self, cx: &AppContext) -> ReplicaId {self.buffer.read(cx).replica_id()diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rsindex ad8434c188c..4a27f457f6b 100644--- a/crates/editor2/src/element.rs+++ b/crates/editor2/src/element.rs@@ -139,8 +139,6 @@ impl EditorElement {register_action(view, cx, Editor::move_right);register_action(view, cx, Editor::move_down);register_action(view, cx, Editor::move_up);- // on_action(cx, Editor::new_file); todo!()- // on_action(cx, Editor::new_file_in_direction); todo!()register_action(view, cx, Editor::cancel);register_action(view, cx, Editor::newline);register_action(view, cx, Editor::newline_above);