Skip to content

Commit

Permalink
Fix dropdown capitalization sorting (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthegreat1 authored Oct 22, 2023
1 parent a2d8b2d commit 3f7b296
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ protected String getValidValue(String value) {
protected String getValidValue(String value, int offset) {
if (offset == -1) return getString();

String valueLowerCase = value.toLowerCase();
return getAllowedValues(value).stream()
.filter(val -> val.toLowerCase().contains(value.toLowerCase()))
.filter(val -> val.toLowerCase().contains(valueLowerCase))
.sorted((s1, s2) -> {
if (s1.startsWith(value) && !s2.startsWith(value)) return -1;
if (!s1.startsWith(value) && s2.startsWith(value)) return 1;
String s1LowerCase = s1.toLowerCase();
String s2LowerCase = s2.toLowerCase();
if (s1LowerCase.startsWith(valueLowerCase) && !s2LowerCase.startsWith(valueLowerCase)) return -1;
if (!s1LowerCase.startsWith(valueLowerCase) && s2LowerCase.startsWith(valueLowerCase)) return 1;
return s1.compareTo(s2);
})
.skip(offset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public static Stream<ResourceLocation> getMatchingItemIdentifiers(String value)
"minecraft:deepslate_diamond_ore", even though the second is lexicographically smaller
*/
.sorted((id1, id2) -> {
String path = (sep == -1 ? value : value.substring(sep + 1));
boolean id1StartsWith = id1.getPath().startsWith(path);
boolean id2StartsWith = id2.getPath().startsWith(path);
String path = (sep == -1 ? value : value.substring(sep + 1)).toLowerCase();
boolean id1StartsWith = id1.getPath().toLowerCase().startsWith(path);
boolean id2StartsWith = id2.getPath().toLowerCase().startsWith(path);
if (id1StartsWith) {
if (id2StartsWith) {
return id1.compareTo(id2);
Expand Down

0 comments on commit 3f7b296

Please sign in to comment.