Add NewFileInDirection

This commit is contained in:
Conrad Irwin 2023-09-20 15:00:41 -06:00
parent 88a32ae48d
commit 6ad1f19a21
3 changed files with 46 additions and 6 deletions

View file

@ -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"
]
}
},
{

View file

@ -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);
}

View file

@ -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
}