Skip to content

Commit

Permalink
Preliminary merge 0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
LennysLounge committed Feb 11, 2024
1 parent 7a25e9b commit 34f159a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 49 deletions.
3 changes: 2 additions & 1 deletion src/dock_state/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,8 @@ impl<Tab> Tree<Tab> {
{
self.nodes.retain_mut(|node| {
node.retain_tabs(predicate.clone());
!node.is_empty()
// TODO(LennyLounge): Fix this
node.iter_tabs().count() > 0
});
}

Expand Down
70 changes: 22 additions & 48 deletions src/dock_state/tree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,21 +285,27 @@ impl<Tab> Node<Tab> {
active,
scroll,
} => {
let tabs: Vec<_> = tabs.iter().filter_map(function).collect();
if tabs.is_empty() {
Node::Empty
} else {
Node::Leaf {
rect: *rect,
viewport: *viewport,
tabs,
active: *active,
scroll: *scroll,
}
}
// TODO(LennysLounge): Fix this
todo!()
// let tabs: Vec<_> = tabs.iter().filter_map(function).collect();
// if tabs.is_empty() {
// Node::Empty
// } else {
// Node::Leaf {
// rect: *rect,
// viewport: *viewport,
// tabs,
// active: *active,
// scroll: *scroll,
// }
// }
}
Node::Empty => Node::Empty,
Node::Vertical { rect, fraction } => Node::Vertical {
Node::Vertical {
rect,
fraction,
above,
below,
} => Node::Vertical {
rect: *rect,
fraction: *fraction,
above: *above,
Expand Down Expand Up @@ -345,41 +351,9 @@ impl<Tab> Node<Tab> {
{
if let Node::Leaf { tabs, .. } = self {
tabs.retain_mut(predicate);
if tabs.is_empty() {
*self = Node::Empty;
}
}
}

/// Returns a new [`Node`] while mapping the tab type.
pub fn map_tabs<F, NewTab>(&self, mut function: F) -> Node<NewTab>
where
F: FnMut(&Tab) -> NewTab,
{
self.filter_map_tabs(move |tab| Some(function(tab)))
}

/// Returns a new [`Node`] while filtering the tab type.
/// If this [`Node`] remains empty, it will change to [`Node::Empty`].
pub fn filter_tabs<F>(&self, mut predicate: F) -> Node<Tab>
where
F: Clone + FnMut(&Tab) -> bool,
Tab: Clone,
{
self.filter_map_tabs(move |tab| predicate(tab).then(|| tab.clone()))
}

/// Removes all tabs for which `predicate` returns `false`.
/// If this [`Node`] remains empty, it will change to [`Node::Empty`].
pub fn retain_tabs<F>(&mut self, predicate: F)
where
F: Clone + FnMut(&mut Tab) -> bool,
{
if let Node::Leaf { tabs, .. } = self {
tabs.retain_mut(predicate);
if tabs.is_empty() {
*self = Node::Empty;
}
}
// TODO(LennyLounge): Fix this
todo!();
}
}

0 comments on commit 34f159a

Please sign in to comment.