Fix tab completion when *not* using %.

- Also allow tab-completion of % pattern when it's the first/only pattern being used
 - Also don't error when attempting to tab complete an invalid percent value
This commit is contained in:
dordsor21
2021-11-18 18:42:19 +00:00
parent 5604000ae2
commit ef61ecccaa
2 changed files with 21 additions and 8 deletions

View File

@ -32,6 +32,8 @@ import java.util.stream.Stream;
public class RichPatternParser extends FaweParser<Pattern> {
private static final java.util.regex.Pattern percentPatternRegex = java.util.regex.Pattern.compile("[0-9]+(\\.[0-9]*)?%.*");
/**
* Create a new rich pattern-parser.
*
@ -110,7 +112,7 @@ public class RichPatternParser extends FaweParser<Pattern> {
pattern = parseFromInput(command.substring(1, end == -1 ? command.length() : end), context);
} else {
int percentIndex = command.indexOf('%');
if (percentIndex != -1) { // Legacy percent pattern
if (percentIndex != -1 && percentPatternRegex.matcher(command).matches()) { // Legacy percent pattern
chance = Expression.compile(command.substring(0, percentIndex)).evaluate();
String value = command.substring(percentIndex + 1);
if (!entry.getValue().isEmpty()) {