mirror of
https://github.com/alibaba/arthas.git
synced 2026-11-30 15:33:59 +00:00
fix CompletionAdaptor lose chars when the last token is blank.
This commit is contained in:
1 parent
a2ef539f4e
commit
349c426bd1
1 file changed
+8
-4
@@ -4,6 +4,7 @@ import com.taobao.arthas.core.shell.cli.CliToken;
|
|||||||
import com.taobao.arthas.core.shell.cli.Completion;
|
import com.taobao.arthas.core.shell.cli.Completion;
|
||||||
import com.taobao.arthas.core.shell.cli.CompletionUtils;
|
import com.taobao.arthas.core.shell.cli.CompletionUtils;
|
||||||
import com.taobao.arthas.core.shell.session.Session;
|
import com.taobao.arthas.core.shell.session.Session;
|
||||||
|
import com.taobao.arthas.core.util.StringUtils;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -42,15 +43,18 @@ class CompletionAdaptor implements Completion {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void complete(List<String> candidates) {
|
public void complete(List<String> candidates) {
|
||||||
|
String lastToken = tokens.get(tokens.size() - 1).value();
|
||||||
|
if(StringUtils.isBlank(lastToken)) {
|
||||||
|
lastToken = "";
|
||||||
|
}
|
||||||
if (candidates.size() > 1) {
|
if (candidates.size() > 1) {
|
||||||
// complete common prefix
|
// complete common prefix
|
||||||
String commonPrefix = CompletionUtils.findLongestCommonPrefix(candidates);
|
String commonPrefix = CompletionUtils.findLongestCommonPrefix(candidates);
|
||||||
if (commonPrefix.length() > 0) {
|
if (commonPrefix.length() > 0) {
|
||||||
CliToken lastToken = tokens.get(tokens.size() - 1);
|
if (!commonPrefix.equals(lastToken)) {
|
||||||
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
|
||||||
if (commonPrefix.length() > lastToken.value().length()) {
|
if (commonPrefix.length() > lastToken.length()) {
|
||||||
String strToComplete = commonPrefix.substring(lastToken.value().length());
|
String strToComplete = commonPrefix.substring(lastToken.length());
|
||||||
completion.complete(io.termd.core.util.Helper.toCodePoints(strToComplete), false);
|
completion.complete(io.termd.core.util.Helper.toCodePoints(strToComplete), false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user