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:
parent
28bcc95468
commit
3752ed294d
19 changed files with 276 additions and 111 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue