Fix message count in folded info

This commit is contained in:
Joscha 2022-08-09 15:12:49 +02:00
parent 87a14eedf2
commit c41ab742d3
2 changed files with 21 additions and 9 deletions

View file

@ -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)

View file

@ -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,12 +108,14 @@ 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 {
if let Some(children) = tree.children(id) {
for child in children { for child in children {
self.layout_subtree(nick, frame, tree, indent + 1, child, blocks); self.layout_subtree(nick, frame, tree, indent + 1, child, blocks);
} }
} }
}
// Trailing ghost cursor, for positioning according to last cursor line // Trailing ghost cursor, for positioning according to last cursor line
if self.last_cursor.refers_to_last_child_of(id) { if self.last_cursor.refers_to_last_child_of(id) {