Skip to content

Commit

Permalink
Fixes for 'filter_tag'
Browse files Browse the repository at this point in the history
- Iterate over all tasks, not just the root elements.
- Consider all descendants of a tag, not just the
  immediate children.
  • Loading branch information
gycsaba96 committed Jul 11, 2024
1 parent 3774871 commit 54238a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 9 additions & 0 deletions GTG/core/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ def get_ancestors(self) -> List['Tag']:
ancestors.append(here)
return ancestors


def get_matching_tags(self) -> List['Tag']:
"""Return the tag with its descendants."""
matching = [self]
for c in self.children:
matching += c.get_matching_tags()
return matching


def __hash__(self):
return id(self)

Expand Down
10 changes: 2 additions & 8 deletions GTG/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,14 +1035,8 @@ def filter_tag(tag: Tag) -> List[Task]:

output = []

for t in self.data:
tags = [_tag for _tag in t.tags]

# Include the tag's children
for _tag in t.tags:
for child in _tag.children:
tags.append(child)

for t in self.lookup.values():
tags = { matching_tag for own_tag in t.tags for matching_tag in own_tag.get_matching_tags() }
if tag in tags:
output.append(t)

Expand Down

0 comments on commit 54238a7

Please sign in to comment.