Allow an empty center group to successfully deserialize into an empty pane.
Fix error when deserializing pane axis which caused it's members.len() > 1 invariant to be violated Fix failure to gain center pane focus when failing to deserialize a center pane entirely Co-authored-by: Max <max@zed.dev>
This commit is contained in:
parent
cd2d593a6c
commit
9bf0a02eae
3 changed files with 26 additions and 11 deletions
|
@ -210,10 +210,10 @@ impl WorkspaceDb {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_center_pane_group(&self, workspace_id: WorkspaceId) -> Result<SerializedPaneGroup> {
|
fn get_center_pane_group(&self, workspace_id: WorkspaceId) -> Result<SerializedPaneGroup> {
|
||||||
self.get_pane_group(workspace_id, None)?
|
Ok(self.get_pane_group(workspace_id, None)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.next()
|
.next()
|
||||||
.context("No center pane group")
|
.unwrap_or_else(|| SerializedPaneGroup::Pane(SerializedPane { active: true, children: vec![] })))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_pane_group(
|
fn get_pane_group(
|
||||||
|
@ -267,7 +267,7 @@ impl WorkspaceDb {
|
||||||
// Filter out panes and pane groups which don't have any children or items
|
// Filter out panes and pane groups which don't have any children or items
|
||||||
.filter(|pane_group| match pane_group {
|
.filter(|pane_group| match pane_group {
|
||||||
Ok(SerializedPaneGroup::Group { children, .. }) => !children.is_empty(),
|
Ok(SerializedPaneGroup::Group { children, .. }) => !children.is_empty(),
|
||||||
Ok(SerializedPaneGroup::Pane(pane)) => !pane.children.is_empty(),
|
Ok(SerializedPaneGroup::Pane(pane)) => !pane.children.is_empty(),
|
||||||
_ => true,
|
_ => true,
|
||||||
})
|
})
|
||||||
.collect::<Result<_>>()
|
.collect::<Result<_>>()
|
||||||
|
|
|
@ -106,7 +106,6 @@ impl SerializedPaneGroup {
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
members.push(new_member);
|
members.push(new_member);
|
||||||
|
|
||||||
current_active_pane = current_active_pane.or(active_pane);
|
current_active_pane = current_active_pane.or(active_pane);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,6 +114,10 @@ impl SerializedPaneGroup {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if members.len() == 1 {
|
||||||
|
return Some((members.remove(0), current_active_pane));
|
||||||
|
}
|
||||||
|
|
||||||
Some((
|
Some((
|
||||||
Member::Axis(PaneAxis {
|
Member::Axis(PaneAxis {
|
||||||
axis: *axis,
|
axis: *axis,
|
||||||
|
@ -130,9 +133,10 @@ impl SerializedPaneGroup {
|
||||||
.deserialize_to(project, &pane, workspace_id, workspace, cx)
|
.deserialize_to(project, &pane, workspace_id, workspace, cx)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if pane.read_with(cx, |pane, _| pane.items().next().is_some()) {
|
if pane.read_with(cx, |pane, _| pane.items_len() != 0) {
|
||||||
Some((Member::Pane(pane.clone()), active.then(|| pane)))
|
Some((Member::Pane(pane.clone()), active.then(|| pane)))
|
||||||
} else {
|
} else {
|
||||||
|
workspace.update(cx, |workspace, cx| workspace.remove_pane(pane, cx));
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2300,6 +2300,9 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(location) = self.location(cx) {
|
if let Some(location) = self.location(cx) {
|
||||||
|
// Load bearing special case:
|
||||||
|
// - with_local_workspace() relies on this to not have other stuff open
|
||||||
|
// when you open your log
|
||||||
if !location.paths().is_empty() {
|
if !location.paths().is_empty() {
|
||||||
let dock_pane = serialize_pane_handle(self.dock.pane(), cx);
|
let dock_pane = serialize_pane_handle(self.dock.pane(), cx);
|
||||||
let center_group = build_serialized_pane_group(&self.center.root, cx);
|
let center_group = build_serialized_pane_group(&self.center.root, cx);
|
||||||
|
@ -2327,9 +2330,14 @@ impl Workspace {
|
||||||
) {
|
) {
|
||||||
cx.spawn(|mut cx| async move {
|
cx.spawn(|mut cx| async move {
|
||||||
if let Some(workspace) = workspace.upgrade(&cx) {
|
if let Some(workspace) = workspace.upgrade(&cx) {
|
||||||
let (project, dock_pane_handle) = workspace.read_with(&cx, |workspace, _| {
|
let (project, dock_pane_handle, old_center_pane) =
|
||||||
(workspace.project().clone(), workspace.dock_pane().clone())
|
workspace.read_with(&cx, |workspace, _| {
|
||||||
});
|
(
|
||||||
|
workspace.project().clone(),
|
||||||
|
workspace.dock_pane().clone(),
|
||||||
|
workspace.last_active_center_pane.clone(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
serialized_workspace
|
serialized_workspace
|
||||||
.dock_pane
|
.dock_pane
|
||||||
|
@ -2365,11 +2373,14 @@ impl Workspace {
|
||||||
cx.focus(workspace.panes.last().unwrap().clone());
|
cx.focus(workspace.panes.last().unwrap().clone());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cx.focus_self();
|
let old_center_handle = old_center_pane.and_then(|weak| weak.upgrade(cx));
|
||||||
|
if let Some(old_center_handle) = old_center_handle {
|
||||||
|
cx.focus(old_center_handle)
|
||||||
|
} else {
|
||||||
|
cx.focus_self()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note, if this is moved after 'set_dock_position'
|
|
||||||
// it causes an infinite loop.
|
|
||||||
if workspace.left_sidebar().read(cx).is_open()
|
if workspace.left_sidebar().read(cx).is_open()
|
||||||
!= serialized_workspace.left_sidebar_open
|
!= serialized_workspace.left_sidebar_open
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue