From ed016dac0eec3f209814653cb9dd7197781ab879 Mon Sep 17 00:00:00 2001 From: Peter Holloway Date: Wed, 29 Nov 2017 18:03:01 +0000 Subject: [PATCH] Recalculate number of columns after lines Prevents the situation where (eg) 9 completion candidates are split 6/3 instead of 5/4 and subsequent columns calculations are incorrect. Fixes #191 --- .../src/main/java/org/jline/reader/impl/LineReaderImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 7b7cdc072..4958351c7 100644 --- a/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java +++ b/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java @@ -4487,8 +4487,10 @@ else if (items instanceof List) { while (c > 1 && c * maxWidth + (c - 1) * MARGIN_BETWEEN_COLUMNS >= width) { c--; } - int columns = c; - int lines = (candidates.size() + columns - 1) / columns; + int lines = (candidates.size() + c - 1) / c; + // Try to minimize the number of columns for the given number of rows + // Prevents eg 9 candiates being split 6/3 instead of 5/4. + final int columns = (candidates.size() + lines - 1) / lines; IntBinaryOperator index; if (isSet(Option.LIST_ROWS_FIRST)) { index = (i, j) -> i * columns + j;