Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add NewFileInDirection
Conrad Irwin6ad1f19a214f
diff --git a/assets/keymaps/vim.json b/assets/keymaps/vim.jsonindex 1a6a752e23f..5db0fe748ef 100644--- a/assets/keymaps/vim.json+++ b/assets/keymaps/vim.json@@ -319,7 +319,17 @@"ctrl-w c": "pane::CloseAllItems","ctrl-w ctrl-c": "pane::CloseAllItems","ctrl-w q": "pane::CloseAllItems",- "ctrl-w ctrl-q": "pane::CloseAllItems"+ "ctrl-w ctrl-q": "pane::CloseAllItems",+ "ctrl-w o": "workspace::CloseInactiveTabsAndPanes",+ "ctrl-w ctrl-o": "workspace::CloseInactiveTabsAndPanes",+ "ctrl-w n": [+ "workspace::NewFileInDirection",+ "Up"+ ],+ "ctrl-w ctrl-n": [+ "workspace::NewFileInDirection",+ "Up"+ ]}},{diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 0827e132640..446ddfeab00 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -103,7 +103,7 @@ use sum_tree::TreeMap;use text::Rope;use theme::{DiagnosticStyle, Theme, ThemeSettings};use util::{post_inc, RangeExt, ResultExt, TryFutureExt};-use workspace::{ItemNavHistory, ViewId, Workspace};+use workspace::{ItemNavHistory, SplitDirection, ViewId, Workspace};use crate::git::diff_hunk_to_display;@@ -363,6 +363,7 @@ pub fn init_settings(cx: &mut AppContext) {pub fn init(cx: &mut AppContext) {init_settings(cx);cx.add_action(Editor::new_file);+ cx.add_action(Editor::new_file_in_direction);cx.add_action(Editor::cancel);cx.add_action(Editor::newline);cx.add_action(Editor::newline_above);@@ -1627,6 +1628,26 @@ 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_action();+ } 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 replica_id(&self, cx: &AppContext) -> ReplicaId {self.buffer.read(cx).replica_id()}@@ -7130,7 +7151,7 @@ impl Editor {);});if split {- workspace.split_item(Box::new(editor), cx);+ workspace.split_item(SplitDirection::Right, Box::new(editor), cx);} else {workspace.add_item(Box::new(editor), cx);}diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex a8e7f12b3a1..6043b946214 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -157,6 +157,9 @@ pub struct ActivatePane(pub usize);#[derive(Clone, Deserialize, PartialEq)]pub struct ActivatePaneInDirection(pub SplitDirection);+#[derive(Clone, Deserialize, PartialEq)]+pub struct NewFileInDirection(pub SplitDirection);+#[derive(Clone, PartialEq, Debug, Deserialize)]#[serde(rename_all = "camelCase")]pub struct SaveAll {@@ -230,6 +233,7 @@ impl_actions!([ActivatePane,ActivatePaneInDirection,+ NewFileInDirection,Toast,OpenTerminal,SaveAll,@@ -1991,8 +1995,13 @@ impl Workspace {.update(cx, |pane, cx| pane.add_item(item, true, true, None, cx));}- pub fn split_item(&mut self, item: Box<dyn ItemHandle>, cx: &mut ViewContext<Self>) {- let new_pane = self.split_pane(self.active_pane.clone(), SplitDirection::Right, cx);+ pub fn split_item(+ &mut self,+ split_direction: SplitDirection,+ item: Box<dyn ItemHandle>,+ cx: &mut ViewContext<Self>,+ ) {+ let new_pane = self.split_pane(self.active_pane.clone(), split_direction, cx);new_pane.update(cx, move |new_pane, cx| {new_pane.add_item(item, true, true, None, cx)})@@ -2170,7 +2179,7 @@ impl Workspace {}let item = cx.add_view(|cx| T::for_project_item(self.project().clone(), project_item, cx));- self.split_item(Box::new(item.clone()), cx);+ self.split_item(SplitDirection::Right, Box::new(item.clone()), cx);item}