From 37df271bea8bf485f36b3de420b6ae9e02d33f7a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Tue, 10 Oct 2017 12:31:52 +0200 Subject: [PATCH] =?utf8?q?Menu:=20Order=20Eintr=C3=A4ge=20automatisch=20Er?= =?utf8?q?g=C3=A4nzen,=20damit=20Sortierung=20stabil=20ist.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Menu.pm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/SL/Menu.pm b/SL/Menu.pm index 800f000b2..0e92cc5b3 100644 --- a/SL/Menu.pm +++ b/SL/Menu.pm @@ -119,6 +119,19 @@ sub build_tree { push @{ $by_parent{ $node->{parent} // '' } //= [] }, $node; } + # autovivify order in by_parent, so that numerical sorting for entries without order + # preserves their order and position with respect to entries with order. + for (values %by_parent) { + my $last_order = 0; + for my $node (@$_) { + if (defined $node->{order} && $node->{order} * 1) { + $last_order = $node->{order}; + } else { + $node->{order} = ++$last_order; + } + } + } + my $tree = { }; $self->{by_id}{''} = $tree; -- 2.20.1