Skip to content

Commit

Permalink
Completer sorting order, fixes #419
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Jan 4, 2020
1 parent 78368e4 commit b4ee6d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2019, the original author or authors.
* Copyright (c) 2002-2020, the original author or authors.
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
Expand Down Expand Up @@ -4643,7 +4643,6 @@ protected Comparator<Candidate> getCandidateComparator(boolean caseInsensitive,
ToIntFunction<String> wordDistance = w -> distance(wdi, caseInsensitive ? w.toLowerCase() : w);
return Comparator
.comparing(Candidate::value, Comparator.comparingInt(wordDistance))
.thenComparing(Candidate::value, Comparator.comparingInt(String::length))
.thenComparing(Comparator.naturalOrder());
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2016, the original author or authors.
* Copyright (c) 2002-2020, the original author or authors.
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
Expand Down Expand Up @@ -136,13 +136,13 @@ public void testCompletePrefix() throws Exception {

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

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

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

@Test
Expand Down

0 comments on commit b4ee6d9

Please sign in to comment.