ratatui_toolkit/primitives/split_layout/methods/
find_parent_split.rs1use crate::primitives::split_layout::enums::layout_node::LayoutNode;
2use crate::primitives::split_layout::PaneId;
3use crate::primitives::split_layout::SplitLayout;
4
5impl SplitLayout {
6 pub(super) fn find_parent_split(&self, pane_id: PaneId) -> Option<(usize, bool)> {
7 let mut stack = vec![(self.root_index, None)];
8
9 while let Some((node_index, parent_index)) = stack.pop() {
10 let Some(node) = self.nodes.get(node_index) else {
11 continue;
12 };
13
14 match node {
15 LayoutNode::Pane { id } => {
16 if *id == pane_id {
17 let Some(parent_index) = parent_index else {
18 return None;
19 };
20 let Some(LayoutNode::Split { first, .. }) = self.nodes.get(parent_index)
21 else {
22 return None;
23 };
24 let is_first = *first == node_index;
25 return Some((parent_index, is_first));
26 }
27 }
28 LayoutNode::Split { first, second, .. } => {
29 stack.push((*second, Some(node_index)));
30 stack.push((*first, Some(node_index)));
31 }
32 }
33 }
34
35 None
36 }
37}