aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin <92656833+kevinthegreat1@users.noreply.github.com>2023-10-22 17:08:24 -0400
committerGitHub <noreply@github.com>2023-10-22 22:08:24 +0100
commit3f7b296b2897b80998d5746fcd170f9bd94ab9e5 (patch)
treedc151dc96dce558d385619bea36a097176632265
parenta2d8b2de90b76c081d55e82853a0ec67f7c868d9 (diff)
downloadYetAnotherConfigLib-3f7b296b2897b80998d5746fcd170f9bd94ab9e5.tar.gz
YetAnotherConfigLib-3f7b296b2897b80998d5746fcd170f9bd94ab9e5.tar.bz2
YetAnotherConfigLib-3f7b296b2897b80998d5746fcd170f9bd94ab9e5.zip
Fix dropdown capitalization sorting (#114)
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/AbstractDropdownController.java9
-rw-r--r--common/src/main/java/dev/isxander/yacl3/gui/utils/ItemRegistryHelper.java6
2 files changed, 9 insertions, 6 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/AbstractDropdownController.java b/common/src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/AbstractDropdownController.java
index 8251f9e..b4e4304 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/AbstractDropdownController.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/AbstractDropdownController.java
@@ -65,11 +65,14 @@ public abstract class AbstractDropdownController<T> implements IStringController
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)
diff --git a/common/src/main/java/dev/isxander/yacl3/gui/utils/ItemRegistryHelper.java b/common/src/main/java/dev/isxander/yacl3/gui/utils/ItemRegistryHelper.java
index 5b52246..5bfbefb 100644
--- a/common/src/main/java/dev/isxander/yacl3/gui/utils/ItemRegistryHelper.java
+++ b/common/src/main/java/dev/isxander/yacl3/gui/utils/ItemRegistryHelper.java
@@ -86,9 +86,9 @@ public final class ItemRegistryHelper {
"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);