Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flatten_tabs_in_tabs #77

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ pub struct SimplificationOptions {
/// If a horizontal container contain another horizontal container, join them?
/// Same for vertical containers. Does NOT apply to grid container or tab containers.
pub join_nested_linear_containers: bool,

// Flatten tabs in tabs?
pub flatten_tabs_in_tabs: bool,
}

impl SimplificationOptions {
Expand All @@ -192,6 +195,7 @@ impl SimplificationOptions {
prune_single_child_containers: false,
all_panes_must_have_tabs: false,
join_nested_linear_containers: false,
flatten_tabs_in_tabs: false,
};
}

Expand All @@ -204,6 +208,7 @@ impl Default for SimplificationOptions {
prune_single_child_containers: true,
all_panes_must_have_tabs: false,
join_nested_linear_containers: true,
flatten_tabs_in_tabs: false,
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,28 @@ impl<Pane> Tiles<Pane> {
}
}
}

if options.flatten_tabs_in_tabs {
let mut found = false;
let mut new_children = Vec::new();

for &child_id in container.children() {
if let Some(Tile::Container(Container::Tabs(child_tabs))) =
self.get(child_id)
{
new_children.extend(child_tabs.children.iter().copied());
found = true;
} else {
new_children.push(child_id);
}
}

if found {
let new_container =
self.insert_new(Tile::Container(Container::new_tabs(new_children)));
return SimplifyAction::Replace(new_container);
}
}
} else {
if options.join_nested_linear_containers {
if let Container::Linear(parent) = container {
Expand Down