Skip to content

Commit 512eaa3

Browse files
akhanfirexo-swf
authored andcommitted
fix: Accented notes aren't well sorted in tree view - MEED-10328 - Meeds-io/meeds#4136 (#1650)
Before this change, when create some notes starting with different letters then create a note that starts with an accent char sample and check notes order in tree view, accented notes are listed at the end of the tree view. To fix this issue, locale-aware sorting using Collator has been applied in TreeUtils.tranformToJson() with PRIMARY strength, ensuring accents and case are ignored during comparison. After this change, notes are correctly ordered alphabetically regardless of accented characters. Resolves Meeds-io/meeds#4136
1 parent 7b964aa commit 512eaa3

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

  • notes-service/src/main/java/org/exoplatform/wiki/tree/utils

notes-service/src/main/java/org/exoplatform/wiki/tree/utils/TreeUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.exoplatform.wiki.tree.utils;
2020

21+
import java.text.Collator;
2122
import java.util.*;
2223
import java.util.stream.Collectors;
2324

@@ -130,6 +131,7 @@ public static List<JsonNodeData> tranformToJson(TreeNode treeNode,
130131
children.add(jsonNodeData);
131132
counter++;
132133
}
134+
sortNodes(children, locale);
133135
return children;
134136
}
135137

@@ -312,4 +314,18 @@ private static ResourceBundleService getResourceBundleService() {
312314
}
313315
return resourceBundleService;
314316
}
317+
318+
private static void sortNodes(List<JsonNodeData> nodes, Locale locale) {
319+
if (nodes == null || nodes.isEmpty()) {
320+
return;
321+
}
322+
Collator collator = Collator.getInstance(locale);
323+
collator.setStrength(Collator.PRIMARY);
324+
325+
nodes.sort((a, b) -> {
326+
String nameA = a.getName() != null ? a.getName() : "";
327+
String nameB = b.getName() != null ? b.getName() : "";
328+
return collator.compare(nameA, nameB);
329+
});
330+
}
315331
}

0 commit comments

Comments
 (0)