Skip to content

Commit

Permalink
Add optional where predicate to OrgTree.findContainingTree
Browse files Browse the repository at this point in the history
  • Loading branch information
amake committed Sep 7, 2024
1 parent bef22de commit 6b2f66a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/src/org/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,16 @@ sealed class OrgTree extends OrgParentNode {

/// Find the immediate parent [OrgSection] or [OrgDocument] of the specified
/// [node].
OrgTree? findContainingTree<T extends OrgNode>(T node) {
OrgTree? findContainingTree<T extends OrgNode>(T node,
{bool Function(OrgTree)? where}) {
where ??= (_) => true;
final found = find<T>((n) => identical(node, n));
if (found == null) return null;
final (node: _, path: path) = found;
return path.reversed.firstWhere((node) => node is OrgTree) as OrgTree;
for (final node in path.reversed) {
if (node is OrgTree && where(node)) return node;
}
return null;
}

/// Get the directory in which attachments are expected to be found for this
Expand Down

0 comments on commit 6b2f66a

Please sign in to comment.