Skip to content

Commit

Permalink
Autocomplete options are shown in random order, fixes #290
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jul 4, 2018
1 parent a802712 commit b5a643d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4412,6 +4412,8 @@ public AttributedString get() {
protected boolean doMenu(List<Candidate> original, String completed, BiFunction<CharSequence, Boolean, CharSequence> escaper) {
// Reorder candidates according to display order
final List<Candidate> possible = new ArrayList<>();
boolean caseInsensitive = isSet(Option.CASE_INSENSITIVE);
original.sort(getCandidateComparator(caseInsensitive, completed));
mergeCandidates(original);
computePost(original, null, possible, completed);

Expand Down
13 changes: 13 additions & 0 deletions reader/src/test/java/org/jline/reader/impl/CompletionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
package org.jline.reader.impl;

import java.io.IOException;
import java.util.Arrays;

import static java.util.Arrays.asList;
import org.jline.reader.Completer;
import org.jline.reader.LineReader.Option;
import org.jline.reader.Reference;
Expand Down Expand Up @@ -131,4 +133,15 @@ public void testCompletePrefix() throws Exception {
assertLine("read and nd", new TestBuffer("read and\033[D\033[D\t\n"));
}

@Test
public void testMenuOrder() {
reader.setCompleter(new StringsCompleter(Arrays.asList("ae_helloWorld", "ad_helloWorld", "ac_helloWorld", "ab_helloWorld", "aa_helloWorld")));
reader.unsetOpt(Option.AUTO_LIST);
reader.setOpt(Option.AUTO_MENU);

assertLine("aa_helloWorld ", new TestBuffer("a\t\n\n"));

assertLine("ab_helloWorld ", new TestBuffer("a\t\t\n\n"));
}

}

0 comments on commit b5a643d

Please sign in to comment.