Implement simplex mask (fixes #437)

This commit is contained in:
Hannes Greule
2020-07-04 17:31:59 +02:00
parent 704e76eb6d
commit ed6f3e7b4a
4 changed files with 77 additions and 29 deletions

View File

@ -22,19 +22,7 @@ public class SimplexPatternParser extends RichParser<Pattern> {
@Override
protected Stream<String> getSuggestions(String argumentInput, int index) {
if (index == 0) {
if (argumentInput.isEmpty()) {
return Stream.of("1", "2", "3", "4", "5", "6", "7", "8", "9");
}
// if already a valid number, suggest more digits
if (isDouble(argumentInput)) {
Stream<String> numbers = Stream.of("", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
if (argumentInput.indexOf('.') == -1) {
numbers = Stream.concat(numbers, Stream.of("."));
}
return numbers.map(s -> argumentInput + s);
}
// no valid input anymore
return Stream.empty();
return suggestPositiveDoubles(argumentInput);
}
if (index == 1) {
return worldEdit.getPatternFactory().getSuggestions(argumentInput).stream();
@ -58,18 +46,4 @@ public class SimplexPatternParser extends RichParser<Pattern> {
throw new InputParseException("Pattern " + inner.getClass().getSimpleName() + " cannot be used with #simplex");
}
}
private static boolean isDouble(String input) {
boolean point = false;
for (char c : input.toCharArray()) {
if (!Character.isDigit(c)) {
if (c == '.' && !point) {
point = true;
} else {
return false;
}
}
}
return true;
}
}