open new buffer (#11203)
Release Notes: - Allow creating new untitled buffers in remote projects TODO: - Add a Test - Fix version number check
This commit is contained in:
+46
-26
@@ -99,7 +99,7 @@ use project::{
|
||||
CodeAction, Completion, FormatTrigger, Item, Location, Project, ProjectPath, ProjectTransaction,
|
||||
};
|
||||
use rand::prelude::*;
|
||||
use rpc::proto::*;
|
||||
use rpc::{proto::*, ErrorExt};
|
||||
use scroll::{Autoscroll, OngoingScroll, ScrollAnchor, ScrollManager, ScrollbarAutoHide};
|
||||
use selections_collection::{resolve_multiple, MutableSelectionsCollection, SelectionsCollection};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -131,7 +131,7 @@ use ui::{
|
||||
};
|
||||
use util::{defer, maybe, post_inc, RangeExt, ResultExt, TryFutureExt};
|
||||
use workspace::item::{ItemHandle, PreviewTabsSettings};
|
||||
use workspace::notifications::NotificationId;
|
||||
use workspace::notifications::{DetachAndPromptErr, NotificationId};
|
||||
use workspace::{
|
||||
searchable::SearchEvent, ItemNavHistory, SplitDirection, ViewId, Workspace, WorkspaceId,
|
||||
};
|
||||
@@ -1610,18 +1610,27 @@ impl Editor {
|
||||
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.add_item_to_active_pane(
|
||||
Box::new(cx.new_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx))),
|
||||
None,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
let create = project.update(cx, |project, cx| project.create_buffer(cx));
|
||||
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
let buffer = create.await?;
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
workspace.add_item_to_active_pane(
|
||||
Box::new(
|
||||
cx.new_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx)),
|
||||
),
|
||||
None,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
})
|
||||
.detach_and_prompt_err("Failed to create buffer", cx, |e, _| match e.error_code() {
|
||||
ErrorCode::RemoteUpgradeRequired => Some(format!(
|
||||
"The remote instance of Zed does not support this yet. It must be upgraded to {}",
|
||||
e.error_tag("required").unwrap_or("the latest version")
|
||||
)),
|
||||
_ => None,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn new_file_in_direction(
|
||||
@@ -1630,18 +1639,29 @@ impl Editor {
|
||||
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.new_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx))),
|
||||
cx,
|
||||
);
|
||||
}
|
||||
let create = project.update(cx, |project, cx| project.create_buffer(cx));
|
||||
let direction = action.0;
|
||||
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
let buffer = create.await?;
|
||||
workspace.update(&mut cx, move |workspace, cx| {
|
||||
workspace.split_item(
|
||||
direction,
|
||||
Box::new(
|
||||
cx.new_view(|cx| Editor::for_buffer(buffer, Some(project.clone()), cx)),
|
||||
),
|
||||
cx,
|
||||
)
|
||||
})?;
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.detach_and_prompt_err("Failed to create buffer", cx, |e, _| match e.error_code() {
|
||||
ErrorCode::RemoteUpgradeRequired => Some(format!(
|
||||
"The remote instance of Zed does not support this yet. It must be upgraded to {}",
|
||||
e.error_tag("required").unwrap_or("the latest version")
|
||||
)),
|
||||
_ => None,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn replica_id(&self, cx: &AppContext) -> ReplicaId {
|
||||
|
||||
@@ -7356,9 +7356,7 @@ async fn test_following(cx: &mut gpui::TestAppContext) {
|
||||
let project = Project::test(fs, ["/file.rs".as_ref()], cx).await;
|
||||
|
||||
let buffer = project.update(cx, |project, cx| {
|
||||
let buffer = project
|
||||
.create_buffer(&sample_text(16, 8, 'a'), None, cx)
|
||||
.unwrap();
|
||||
let buffer = project.create_local_buffer(&sample_text(16, 8, 'a'), None, cx);
|
||||
cx.new_model(|cx| MultiBuffer::singleton(buffer, cx))
|
||||
});
|
||||
let leader = cx.add_window(|cx| build_editor(buffer.clone(), cx));
|
||||
@@ -7565,12 +7563,8 @@ async fn test_following_with_multiple_excerpts(cx: &mut gpui::TestAppContext) {
|
||||
|
||||
let (buffer_1, buffer_2) = project.update(cx, |project, cx| {
|
||||
(
|
||||
project
|
||||
.create_buffer("abc\ndef\nghi\njkl\n", None, cx)
|
||||
.unwrap(),
|
||||
project
|
||||
.create_buffer("mno\npqr\nstu\nvwx\n", None, cx)
|
||||
.unwrap(),
|
||||
project.create_local_buffer("abc\ndef\nghi\njkl\n", None, cx),
|
||||
project.create_local_buffer("mno\npqr\nstu\nvwx\n", None, cx),
|
||||
)
|
||||
});
|
||||
|
||||
|
||||
+18
-22
@@ -108,10 +108,9 @@ mod tests {
|
||||
let project = Project::test(fs, [], cx).await;
|
||||
|
||||
// buffer has two modified hunks with two rows each
|
||||
let buffer_1 = project
|
||||
.update(cx, |project, cx| {
|
||||
project.create_buffer(
|
||||
"
|
||||
let buffer_1 = project.update(cx, |project, cx| {
|
||||
project.create_local_buffer(
|
||||
"
|
||||
1.zero
|
||||
1.ONE
|
||||
1.TWO
|
||||
@@ -120,13 +119,12 @@ mod tests {
|
||||
1.FIVE
|
||||
1.six
|
||||
"
|
||||
.unindent()
|
||||
.as_str(),
|
||||
None,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
.unindent()
|
||||
.as_str(),
|
||||
None,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
buffer_1.update(cx, |buffer, cx| {
|
||||
buffer.set_diff_base(
|
||||
Some(
|
||||
@@ -146,10 +144,9 @@ mod tests {
|
||||
});
|
||||
|
||||
// buffer has a deletion hunk and an insertion hunk
|
||||
let buffer_2 = project
|
||||
.update(cx, |project, cx| {
|
||||
project.create_buffer(
|
||||
"
|
||||
let buffer_2 = project.update(cx, |project, cx| {
|
||||
project.create_local_buffer(
|
||||
"
|
||||
2.zero
|
||||
2.one
|
||||
2.two
|
||||
@@ -158,13 +155,12 @@ mod tests {
|
||||
2.five
|
||||
2.six
|
||||
"
|
||||
.unindent()
|
||||
.as_str(),
|
||||
None,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
.unindent()
|
||||
.as_str(),
|
||||
None,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
buffer_2.update(cx, |buffer, cx| {
|
||||
buffer.set_diff_base(
|
||||
Some(
|
||||
|
||||
@@ -97,15 +97,19 @@ pub fn expand_macro_recursively(
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let buffer = project.update(&mut cx, |project, cx| {
|
||||
project.create_buffer(¯o_expansion.expansion, Some(rust_language), cx)
|
||||
})??;
|
||||
let buffer = project
|
||||
.update(&mut cx, |project, cx| project.create_buffer(cx))?
|
||||
.await?;
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
let buffer = cx.new_model(|cx| {
|
||||
buffer.update(cx, |buffer, cx| {
|
||||
buffer.edit([(0..0, macro_expansion.expansion)], None, cx);
|
||||
buffer.set_language(Some(rust_language), cx)
|
||||
});
|
||||
let multibuffer = cx.new_model(|cx| {
|
||||
MultiBuffer::singleton(buffer, cx).with_title(macro_expansion.name)
|
||||
});
|
||||
workspace.add_item_to_active_pane(
|
||||
Box::new(cx.new_view(|cx| Editor::for_multibuffer(buffer, Some(project), cx))),
|
||||
Box::new(cx.new_view(|cx| Editor::for_multibuffer(multibuffer, Some(project), cx))),
|
||||
None,
|
||||
cx,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user