From 3bb30026f6c89cd85ae7a244b06988e3890bf8da Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Mon, 6 Nov 2023 15:32:40 +0100 Subject: [PATCH] fix(resurrection): properly serialize certain edge cases (#2907) * fix(resurrection): properly serialize certain edge cases * style(fmt): rustfmt --- zellij-utils/src/session_serialization.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/zellij-utils/src/session_serialization.rs b/zellij-utils/src/session_serialization.rs index fc82c5bd95..0cd973285b 100644 --- a/zellij-utils/src/session_serialization.rs +++ b/zellij-utils/src/session_serialization.rs @@ -104,16 +104,17 @@ fn stringify_tab( pane_contents: &mut BTreeMap, ) -> Option { 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")); @@ -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, @@ -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); @@ -260,6 +263,7 @@ fn stringify_pane_title_and_attributes( focus: Option, initial_pane_contents: &Option, pane_contents: &mut BTreeMap, + has_children: bool, ) -> String { let mut kdl_string = match (&command, &edit) { (Some(command), _) => format!("pane command=\"{}\"", command), @@ -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)); } } @@ -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, @@ -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);