Skip to content

Commit

Permalink
Fix #214
Browse files Browse the repository at this point in the history
  • Loading branch information
isXander committed Oct 22, 2024
1 parent b2293d3 commit eac2944
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public Option<T> option() {
@Override
public void setFromString(String value) {
try {
setPendingValue(Mth.clamp(NUMBER_FORMAT.parse(value).doubleValue(), min(), max()));
String transformed = transformInput(value);
setPendingValue(Mth.clamp(NUMBER_FORMAT.parse(transformed).doubleValue(), min(), max()));
} catch (ParseException ignore) {
YACLConstants.LOGGER.warn("Failed to parse number: {}", value);
}
Expand All @@ -57,7 +58,8 @@ public double pendingValue() {

@Override
public boolean isInputValid(String input) {
input = input.replace(DECIMAL_FORMAT_SYMBOLS.getGroupingSeparator() + "", "");
input = transformInput(input);

ParsePosition parsePosition = new ParsePosition(0);
NUMBER_FORMAT.parse(input, parsePosition);
return parsePosition.getIndex() == input.length();
Expand All @@ -77,4 +79,11 @@ public AbstractWidget provideWidget(YACLScreen screen, Dimension<Integer> widget
public double interval() {
return -1;
}

protected String transformInput(String input) {
if (input.isEmpty()) input = "0";
if (input.equals("-")) input = "-0";

return input.replace(DECIMAL_FORMAT_SYMBOLS.getGroupingSeparator() + "", "");
}
}

0 comments on commit eac2944

Please sign in to comment.