Skip to content

Commit

Permalink
fix CompletionAdaptor lose chars when the last token is blank.
Browse files Browse the repository at this point in the history
  • Loading branch information
hengyunabc committed Feb 7, 2019
1 parent a2ef539 commit 349c426
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.taobao.arthas.core.shell.cli.Completion;
import com.taobao.arthas.core.shell.cli.CompletionUtils;
import com.taobao.arthas.core.shell.session.Session;
import com.taobao.arthas.core.util.StringUtils;

import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -42,15 +43,18 @@ public List<CliToken> lineTokens() {

@Override
public void complete(List<String> candidates) {
String lastToken = tokens.get(tokens.size() - 1).value();
if(StringUtils.isBlank(lastToken)) {
lastToken = "";
}
if (candidates.size() > 1) {
// complete common prefix
String commonPrefix = CompletionUtils.findLongestCommonPrefix(candidates);
if (commonPrefix.length() > 0) {
CliToken lastToken = tokens.get(tokens.size() - 1);
if (!commonPrefix.equals(lastToken.value())) {
if (!commonPrefix.equals(lastToken)) {
// only complete if the common prefix is longer than the last token
if (commonPrefix.length() > lastToken.value().length()) {
String strToComplete = commonPrefix.substring(lastToken.value().length());
if (commonPrefix.length() > lastToken.length()) {
String strToComplete = commonPrefix.substring(lastToken.length());
completion.complete(io.termd.core.util.Helper.toCodePoints(strToComplete), false);
return;
}
Expand Down

0 comments on commit 349c426

Please sign in to comment.