Fix message count in folded info
This commit is contained in:
parent
87a14eedf2
commit
c41ab742d3
2 changed files with 21 additions and 9 deletions
|
|
@ -94,6 +94,15 @@ impl<M: Msg> Tree<M> {
|
||||||
self.children.get(id).map(|c| c as &[M::Id])
|
self.children.get(id).map(|c| c as &[M::Id])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn subtree_size(&self, id: &M::Id) -> usize {
|
||||||
|
let children = self.children(id).unwrap_or_default();
|
||||||
|
let mut result = children.len();
|
||||||
|
for child in children {
|
||||||
|
result += self.subtree_size(child);
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
pub fn siblings(&self, id: &M::Id) -> Option<&[M::Id]> {
|
pub fn siblings(&self, id: &M::Id) -> Option<&[M::Id]> {
|
||||||
if let Some(parent) = self.parent(id) {
|
if let Some(parent) = self.parent(id) {
|
||||||
self.children(&parent)
|
self.children(&parent)
|
||||||
|
|
|
||||||
|
|
@ -90,12 +90,13 @@ impl<M: Msg + ChatMsg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
||||||
blocks.blocks_mut().push_back(block);
|
blocks.blocks_mut().push_back(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Last part of message body if message is folded
|
||||||
let folded = self.folded.contains(id);
|
let folded = self.folded.contains(id);
|
||||||
let children = tree.children(id);
|
let folded_info = if folded {
|
||||||
let folded_info = children
|
Some(tree.subtree_size(id)).filter(|s| *s > 0)
|
||||||
.filter(|_| folded)
|
} else {
|
||||||
.map(|c| c.len())
|
None
|
||||||
.filter(|c| *c > 0);
|
};
|
||||||
|
|
||||||
// Main message body
|
// Main message body
|
||||||
let highlighted = self.cursor.refers_to(id);
|
let highlighted = self.cursor.refers_to(id);
|
||||||
|
|
@ -107,10 +108,12 @@ impl<M: Msg + ChatMsg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
||||||
let block = Block::new(frame, BlockId::Msg(id.clone()), widget);
|
let block = Block::new(frame, BlockId::Msg(id.clone()), widget);
|
||||||
blocks.blocks_mut().push_back(block);
|
blocks.blocks_mut().push_back(block);
|
||||||
|
|
||||||
// Children recursively (if not folded)
|
// Children, recursively
|
||||||
if let Some(children) = children.filter(|_| !folded) {
|
if !folded {
|
||||||
for child in children {
|
if let Some(children) = tree.children(id) {
|
||||||
self.layout_subtree(nick, frame, tree, indent + 1, child, blocks);
|
for child in children {
|
||||||
|
self.layout_subtree(nick, frame, tree, indent + 1, child, blocks);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue