Item13910: TreePlugin wrong sorting
Priority: Normal
Current State: Confirmed
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: TreePlugin
Branches:
Repo
- Install TreePlugin
- Create few unicode named topics
- the WebTopicList shows correct sorting
- the TREEVIEW macro wrong
- screenshots attached
- look at 4 character topic names..
screenshot - WebIndex - ok sort:
|
TREEVIEW screenshot - wrong sort:
|
--
JozefMojzis - 03 Jan 2016
Needs the same fix used for other sort code (not tested).
diff --git a/lib/Foswiki/Plugins/TreePlugin.pm b/lib/Foswiki/Plugins/TreePlugin.pm
index 43d52de..53e157d 100644
--- a/lib/Foswiki/Plugins/TreePlugin.pm
+++ b/lib/Foswiki/Plugins/TreePlugin.pm
@@ -284,7 +284,7 @@ sub HandleTreeTag {
#Second loop:
# * Create nodes relationship
- foreach my $nodeId ( sort keys %nodes ) {
+ foreach my $nodeId ( sort { NFKD($a) cmp NFKD($b) } keys %nodes ) {
my $node = $nodes{$nodeId};
#Make sure we don't set a parent to the web root otherwise we just go in an infinite loop while rendering
@@ -389,8 +389,8 @@ sub createCache {
return;
}
- foreach my $nodeId ( sort keys %$nodesRef ) {
- my $node = $nodesRef->{$nodeId};
+ foreach my $nodeId ( sort { NFKD($a) cmp NFKD($b) } keys %$nodesRef ) {
+ my $node = $nodesRef->{$nodeId};
#Foswiki::Func::writeDebug( "- ${pluginName} Building cache for: " . $node->data('topic') ) if $debug;
if ( !defined $webRoot
--
GeorgeClark - 03 Jan 2016
This works nicely. Just need add the
use Unicode::Normalize;
to the top.
--
JozefMojzis - 03 Jan 2016
Maybe would be worth adding to
Foswiki::
namespace something as
namesort
and everywhere where need to change the sorting to
NFKD
use the new function, e.g. instead of the
foreach my $nodeId ( sort { NFKD($a) cmp NFKD($b) } keys %nodes ) {
use
for my $nodeId ( sort Foswiki::namesort keys %nodes ) {
and the the Foswiki package could contain
use Unicode::Normalize;
sub namesort { NFKD($a) cmp NFKD($b) }};
This allows
easily change the
name sorting
in the future, to something more advanced, e.g. locale based sorting and so on, without the need everywhere again edit the sorting rule...
--
JozefMojzis - 04 Jan 2016
Nice idea, but we'd need to get this added to the API formally, and extensions would not be backwards compatible.
--
GeorgeClark - 05 Jan 2016
Confirming this. Note also that there are performance issues to the recommended sort above, Alternative suggested by
MichaelDaum.
--
GeorgeClark - 25 Sep 2016