Skip to content

Commit

Permalink
fix(resurrection): properly serialize certain edge cases (zellij-org#…
Browse files Browse the repository at this point in the history
…2907)

* fix(resurrection): properly serialize certain edge cases

* style(fmt): rustfmt
  • Loading branch information
imsnif authored Nov 6, 2023
1 parent 3ae742d commit 3bb3002
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions zellij-utils/src/session_serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,17 @@ fn stringify_tab(
pane_contents: &mut BTreeMap<String, String>,
) -> Option<String> {
let mut kdl_string = String::new();
// let tiled_panes_layout = get_tiled_panes_layout_from_panegeoms(tiled_panes, None);
match get_tiled_panes_layout_from_panegeoms(tiled_panes, None) {
Some(tiled_panes_layout) => {
let floating_panes_layout = get_floating_panes_layout_from_panegeoms(floating_panes);
let tiled_panes =
if &tiled_panes_layout.children_split_direction != &SplitDirection::default() {
vec![tiled_panes_layout]
} else {
tiled_panes_layout.children
};
let tiled_panes = if &tiled_panes_layout.children_split_direction
!= &SplitDirection::default()
|| tiled_panes_layout.children_are_stacked
{
vec![tiled_panes_layout]
} else {
tiled_panes_layout.children
};
let mut tab_attributes = vec![format!("name=\"{}\"", tab_name,)];
if is_focused {
tab_attributes.push(format!("focus=true"));
Expand Down Expand Up @@ -182,6 +183,7 @@ fn kdl_string_from_tiled_pane(
let (plugin, plugin_config) = extract_plugin_and_config(&layout.run);
let (edit, _line_number) = extract_edit_and_line_number(&layout.run);
let cwd = layout.run.as_ref().and_then(|r| r.get_cwd());
let has_children = layout.external_children_index.is_some() || !layout.children.is_empty();
let mut kdl_string = stringify_pane_title_and_attributes(
&command,
&edit,
Expand All @@ -190,6 +192,7 @@ fn kdl_string_from_tiled_pane(
layout.focus,
&layout.pane_initial_contents,
pane_contents,
has_children,
);

stringify_tiled_layout_attributes(&layout, ignore_size, &mut kdl_string);
Expand Down Expand Up @@ -260,6 +263,7 @@ fn stringify_pane_title_and_attributes(
focus: Option<bool>,
initial_pane_contents: &Option<String>,
pane_contents: &mut BTreeMap<String, String>,
has_children: bool,
) -> String {
let mut kdl_string = match (&command, &edit) {
(Some(command), _) => format!("pane command=\"{}\"", command),
Expand All @@ -271,7 +275,7 @@ fn stringify_pane_title_and_attributes(
}
if let Some(cwd) = cwd {
let path = cwd.display().to_string();
if !path.is_empty() {
if !path.is_empty() && !has_children {
kdl_string.push_str(&format!(" cwd=\"{}\"", path));
}
}
Expand Down Expand Up @@ -549,6 +553,7 @@ fn kdl_string_from_floating_pane(
let (plugin, plugin_config) = extract_plugin_and_config(&layout.run);
let (edit, _line_number) = extract_edit_and_line_number(&layout.run);
let cwd = layout.run.as_ref().and_then(|r| r.get_cwd());
let has_children = false;
let mut kdl_string = stringify_pane_title_and_attributes(
&command,
&edit,
Expand All @@ -557,6 +562,7 @@ fn kdl_string_from_floating_pane(
layout.focus,
&layout.pane_initial_contents,
pane_contents,
has_children,
);
kdl_string.push_str(" {\n");
stringify_start_suspended(&command, &mut kdl_string);
Expand Down

0 comments on commit 3bb3002

Please sign in to comment.