Add NewFileInDirection
This commit is contained in:
parent
88a32ae48d
commit
6ad1f19a21
3 changed files with 46 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue