Update total count tracking to always consider the wrapper object

This commit is contained in:
Rapptz
2025-08-21 22:20:12 -04:00
parent 0309aac335
commit 9bda89b0d6
6 changed files with 28 additions and 18 deletions

View File

@ -234,6 +234,11 @@ class Container(Item[V]):
def width(self):
return 5
@property
def _total_count(self) -> int:
# 1 for self and all children
return 1 + len(tuple(self.walk_children()))
def _is_v2(self) -> bool:
return True
@ -313,10 +318,8 @@ class Container(Item[V]):
if not isinstance(item, Item):
raise TypeError(f'expected Item not {item.__class__.__name__}')
if item._has_children() and self._view:
self._view._add_count(len(tuple(item.walk_children()))) # type: ignore
elif self._view:
self._view._add_count(1)
if self._view:
self._view._add_count(item._total_count)
self._children.append(item)
item._update_view(self.view)
@ -341,10 +344,7 @@ class Container(Item[V]):
pass
else:
if self._view:
if item._has_children():
self._view._add_count(-len(tuple(item.walk_children()))) # type: ignore
else:
self._view._add_count(-1)
self._view._add_count(-item._total_count)
return self
def find_item(self, id: int, /) -> Optional[Item[V]]: