Skip to content

Commit

Permalink
TailTipWidgets: fix IndexOutOfBoundsException exception, fixes #482
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Dec 6, 2019
1 parent 94b6fcf commit 347b1c2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions builtins/src/main/java/org/jline/builtins/Widgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,6 @@ private void doCommandTailTip(String widget, CmdDesc cmdDesc, List<String> args)
}
}
String lastArg = !prevChar().equals(" ") ? args.get(args.size() - 1) : "";
if (lastArg.startsWith("-")) {
}
int bpsize = argnum;
boolean doTailTip = true;
boolean noCompleters = false;
Expand Down Expand Up @@ -1320,7 +1318,7 @@ public List<AttributedString> getOptionDescription(String opt, int descriptionSi
AttributedStringBuilder asb = new AttributedStringBuilder().tabs(tabs);
asb.append(highlightOption(key));
asb.append("\t");
asb.append(optsDesc.get(key).get(0));
asb.append(optionDescription(key));
out.add(asb.toAttributedString());
}
} else if (matched.size() <= 2*descriptionSize) {
Expand All @@ -1335,7 +1333,7 @@ public List<AttributedString> getOptionDescription(String opt, int descriptionSi
if (row < descriptionSize) {
asb.append(highlightOption(key));
asb.append("\t");
asb.append(optsDesc.get(key).get(0));
asb.append(optionDescription(key));
if (asb.columnLength() > columnWidth - 2) {
AttributedString trunc = asb.columnSubSequence(0, columnWidth - 5);
asb = new AttributedStringBuilder().tabs(tabs);
Expand All @@ -1352,7 +1350,7 @@ public List<AttributedString> getOptionDescription(String opt, int descriptionSi
asb.append(keyList.get(row - descriptionSize));
asb.append(highlightOption(key));
asb.append("\t");
asb.append(optsDesc.get(key).get(0));
asb.append(optionDescription(key));
keyList.remove(row - descriptionSize);
keyList.add(row - descriptionSize, asb.toAttributedString());

Expand Down Expand Up @@ -1382,6 +1380,10 @@ public List<AttributedString> getOptionDescription(String opt, int descriptionSi
}
return out;
}

private AttributedString optionDescription(String key) {
return optsDesc.get(key).size() > 0 ? optsDesc.get(key).get(0) : new AttributedString("");
}

private AttributedString highlightOption(String option) {
return new AttributedStringBuilder()
Expand Down

0 comments on commit 347b1c2

Please sign in to comment.