fix long name option completion. close #318

This commit is contained in:
hengyunabc
2018-11-25 23:42:23 +08:00
parent db78b670d6
commit 361bda07ef
2 changed files with 11 additions and 4 deletions
@@ -99,7 +99,12 @@ public class CompletionUtils {
} else {
String commonPrefix = CompletionUtils.findLongestCommonPrefix(candidates);
if (commonPrefix.length() > 0) {
completion.complete(commonPrefix, false);
if (commonPrefix.length() == prefix.length()) {
completion.complete(candidates);
} else {
completion.complete(commonPrefix.substring(prefix.length(), commonPrefix.length()), false);
}
} else {
completion.complete(candidates);
}
@@ -49,9 +49,11 @@ class CompletionAdaptor implements Completion {
CliToken lastToken = tokens.get(tokens.size() - 1);
if (!commonPrefix.equals(lastToken.value())) {
// only complete if the common prefix is longer than the last token
String strToComplete = commonPrefix.substring(lastToken.value().length());
completion.complete(io.termd.core.util.Helper.toCodePoints(strToComplete), false);
return;
if (commonPrefix.length() > lastToken.value().length()) {
String strToComplete = commonPrefix.substring(lastToken.value().length());
completion.complete(io.termd.core.util.Helper.toCodePoints(strToComplete), false);
return;
}
}
}
}