fix long name option completion. close #318

pull/331/head
hengyunabc 6 years ago
parent db78b670d6
commit 361bda07ef

@ -99,7 +99,12 @@ public class CompletionUtils {
} else { } else {
String commonPrefix = CompletionUtils.findLongestCommonPrefix(candidates); String commonPrefix = CompletionUtils.findLongestCommonPrefix(candidates);
if (commonPrefix.length() > 0) { 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 { } else {
completion.complete(candidates); completion.complete(candidates);
} }

@ -49,9 +49,11 @@ class CompletionAdaptor implements Completion {
CliToken lastToken = tokens.get(tokens.size() - 1); CliToken lastToken = tokens.get(tokens.size() - 1);
if (!commonPrefix.equals(lastToken.value())) { if (!commonPrefix.equals(lastToken.value())) {
// only complete if the common prefix is longer than the last token // only complete if the common prefix is longer than the last token
String strToComplete = commonPrefix.substring(lastToken.value().length()); if (commonPrefix.length() > lastToken.value().length()) {
completion.complete(io.termd.core.util.Helper.toCodePoints(strToComplete), false); String strToComplete = commonPrefix.substring(lastToken.value().length());
return; completion.complete(io.termd.core.util.Helper.toCodePoints(strToComplete), false);
return;
}
} }
} }
} }

Loading…
Cancel
Save