isXander / YetAnotherConfigLib

YetAnotherConfigLib (yacl) is just that. A builder-based configuration library for Minecraft.
GNU Lesser General Public License v3.0
96 stars 37 forks source link

String dropdowns prioritize capitalization over starting with #113

Closed kevinthegreat1 closed 10 months ago

kevinthegreat1 commented 11 months ago

Options containing the correct capitalization can be prioritized over options that starts with the string.

Example

Screenshot 2023-10-02 at 22 31 50

Analysis

In AbstractDropdownController#getValidValue, the filter calls value.toLowerCase() but the checks in sorted() does not call toLowerCase().

return getAllowedValues(value).stream()
        .filter(val -> val.toLowerCase().contains(value.toLowerCase()))
        .sorted((s1, s2) -> {
            if (s1.startsWith(value) && !s2.startsWith(value)) return -1;
            if (!s1.startsWith(value) && s2.startsWith(value)) return 1;
            return s1.compareTo(s2);
        })
        .skip(offset)
        .findFirst()
        .orElseGet(this::getString);