Merge branch 'main' into rpc
This commit is contained in:
+40
-6
@@ -30,6 +30,7 @@ use std::{
|
||||
pub fn init(cx: &mut MutableAppContext) {
|
||||
cx.add_global_action("workspace:open", open);
|
||||
cx.add_global_action("workspace:open_paths", open_paths);
|
||||
cx.add_global_action("workspace:new_file", open_new);
|
||||
cx.add_action("workspace:save", Workspace::save_active_item);
|
||||
cx.add_action("workspace:debug_elements", Workspace::debug_elements);
|
||||
cx.add_action("workspace:new_file", Workspace::open_new_file);
|
||||
@@ -100,6 +101,19 @@ fn open_paths(params: &OpenParams, cx: &mut MutableAppContext) {
|
||||
});
|
||||
}
|
||||
|
||||
fn open_new(app_state: &AppState, cx: &mut MutableAppContext) {
|
||||
cx.add_window(|cx| {
|
||||
let mut view = Workspace::new(
|
||||
app_state.settings.clone(),
|
||||
app_state.language_registry.clone(),
|
||||
app_state.rpc.clone(),
|
||||
cx,
|
||||
);
|
||||
view.open_new_file(&app_state, cx);
|
||||
view
|
||||
});
|
||||
}
|
||||
|
||||
pub trait Item: Entity + Sized {
|
||||
type View: ItemView;
|
||||
|
||||
@@ -479,7 +493,7 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_new_file(&mut self, _: &(), cx: &mut ViewContext<Self>) {
|
||||
pub fn open_new_file(&mut self, _: &AppState, cx: &mut ViewContext<Self>) {
|
||||
let buffer = cx.add_model(|cx| Buffer::new(0, "", cx));
|
||||
let buffer_view =
|
||||
cx.add_view(|cx| Editor::for_buffer(buffer.clone(), self.settings.clone(), cx));
|
||||
@@ -1173,9 +1187,9 @@ mod tests {
|
||||
let app_state = cx.read(build_app_state);
|
||||
let (_, workspace) = cx.add_window(|cx| {
|
||||
let mut workspace = Workspace::new(
|
||||
app_state.settings,
|
||||
app_state.language_registry,
|
||||
app_state.rpc,
|
||||
app_state.settings.clone(),
|
||||
app_state.language_registry.clone(),
|
||||
app_state.rpc.clone(),
|
||||
cx,
|
||||
);
|
||||
workspace.add_worktree(dir.path(), cx);
|
||||
@@ -1194,7 +1208,7 @@ mod tests {
|
||||
|
||||
// Create a new untitled buffer
|
||||
let editor = workspace.update(&mut cx, |workspace, cx| {
|
||||
workspace.open_new_file(&(), cx);
|
||||
workspace.open_new_file(&app_state, cx);
|
||||
workspace
|
||||
.active_item(cx)
|
||||
.unwrap()
|
||||
@@ -1202,6 +1216,7 @@ mod tests {
|
||||
.downcast::<Editor>()
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
editor.update(&mut cx, |editor, cx| {
|
||||
assert!(!editor.is_dirty(cx.as_ref()));
|
||||
assert_eq!(editor.title(cx.as_ref()), "untitled");
|
||||
@@ -1244,7 +1259,7 @@ mod tests {
|
||||
// Open the same newly-created file in another pane item. The new editor should reuse
|
||||
// the same buffer.
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
workspace.open_new_file(&(), cx);
|
||||
workspace.open_new_file(&app_state, cx);
|
||||
workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx);
|
||||
assert!(workspace
|
||||
.open_entry((tree.id(), Path::new("the-new-name").into()), cx)
|
||||
@@ -1263,6 +1278,25 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_new_empty_workspace(mut cx: gpui::TestAppContext) {
|
||||
cx.update(init);
|
||||
|
||||
let app_state = cx.read(build_app_state);
|
||||
cx.dispatch_global_action("workspace:new_file", app_state);
|
||||
let window_id = *cx.window_ids().first().unwrap();
|
||||
let workspace = cx.root_view::<Workspace>(window_id).unwrap();
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
let editor = workspace
|
||||
.active_item(cx)
|
||||
.unwrap()
|
||||
.to_any()
|
||||
.downcast::<Editor>()
|
||||
.unwrap();
|
||||
assert!(editor.read(cx).text(cx.as_ref()).is_empty());
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_pane_actions(mut cx: gpui::TestAppContext) {
|
||||
cx.update(|cx| pane::init(cx));
|
||||
|
||||
Reference in New Issue
Block a user