From ae74cf78a70ba5fbde2ef17cd5e6ebe10c073624 Mon Sep 17 00:00:00 2001 From: mattirn Date: Sat, 4 Jan 2020 11:13:49 +0100 Subject: [PATCH] Completer sorting order, fixes #419 --- .../main/java/org/jline/reader/impl/LineReaderImpl.java | 6 +++--- .../test/java/org/jline/reader/impl/CompletionTest.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java b/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java index fb7378592..aeb80bbbe 100644 --- a/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java +++ b/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java @@ -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. @@ -4643,8 +4643,8 @@ protected Comparator getCandidateComparator(boolean caseInsensitive, ToIntFunction 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()); + .thenComparing(Comparator.naturalOrder()) + .thenComparing(Candidate::value, Comparator.comparingInt(String::length)); } protected String getOthersGroupName() { diff --git a/reader/src/test/java/org/jline/reader/impl/CompletionTest.java b/reader/src/test/java/org/jline/reader/impl/CompletionTest.java index d5ee3e5ef..bf80c8571 100644 --- a/reader/src/test/java/org/jline/reader/impl/CompletionTest.java +++ b/reader/src/test/java/org/jline/reader/impl/CompletionTest.java @@ -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. @@ -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