Skip to content

Commit d18857e

Browse files
committed
Make Tree Viewer node sorting optional
1 parent aee97d4 commit d18857e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/Terminal/Widgets/Viewer/Tree.rakumod

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ my class DisplayLeaf does DisplayNode {
2626
my class DisplayParent does DisplayNode {
2727
has DisplayNode:D @.children;
2828
has Bool:D $.expanded = False;
29-
has &.sort-by is required;
29+
has &.sort-by;
3030

3131
#| Refresh children from volatile data and recreate DisplayNodes as needed
3232
method refresh-children() {
33-
my $depth = $!depth + 1;
34-
@!children = $.data.children(:refresh).sort(&!sort-by).map: {
33+
my $depth = $!depth + 1;
34+
my &create := {
3535
$_ ~~ VTree::Parent
3636
?? DisplayParent.new(parent => self, data => $_, :$depth, :&!sort-by)
3737
!! DisplayLeaf.new( parent => self, data => $_, :$depth)
38-
}
38+
};
39+
@!children = &!sort-by
40+
?? $.data.children(:refresh).sort(&!sort-by).map(&create)
41+
!! $.data.children(:refresh).map(&create)
3942
}
4043

4144
#| Toggle expanded state (using set-expanded)
@@ -65,7 +68,7 @@ class Terminal::Widgets::Viewer::Tree
6568
has VTree::Node $.root;
6669
has DisplayParent $.display-root is built(False);
6770
has DisplayNode $.current-node is built(False);
68-
has &.sort-by = *.short-name;
71+
has &.sort-by;
6972
has &.process-click;
7073

7174
has @!flat-node-cache;

0 commit comments

Comments
 (0)