branch: master
commit 1a5b259ba40f0439320b15c896b57b74fdd54de9
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
Fix the minibuffer being too small with enough candidates
* ivy.el (ivy--format): Fix the bug of getting the minibuffer height
less than `ivy-height' when `ivy--index' was between `ivy--length'
and (- ivy--length (/ ivy--height 2)).
* ivy-test.el (ivy--format): Add test.
---
ivy-test.el | 19 +++++++++++++++++++
ivy.el | 3 ++-
2 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/ivy-test.el b/ivy-test.el
index 1062cd8..af0fc60 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -95,3 +95,22 @@
"^"))
(should (string= (ivy--regex-fuzzy "$")
"$")))
+
+(ert-deftest ivy--format ()
+ (should (string= (let ((ivy--index 10)
+ (ivy-format-function (lambda (x) (mapconcat
#'identity x "\n")))
+ (cands '("NAME"
+ "SYNOPSIS"
+ "DESCRIPTION"
+ "FUNCTION LETTERS"
+ "SWITCHES"
+ "DIAGNOSTICS"
+ "EXAMPLE 1"
+ "EXAMPLE 2"
+ "EXAMPLE 3"
+ "SEE ALSO"
+ "AUTHOR")))
+ (ivy--format cands))
+ #("\nDESCRIPTION\nFUNCTION
LETTERS\nSWITCHES\nDIAGNOSTICS\nEXAMPLE 1\nEXAMPLE 2\nEXAMPLE 3\nSEE
ALSO\nAUTHOR"
+ 0 90 (read-only nil)
+ 90 96 (face ivy-current-match read-only nil)))))
diff --git a/ivy.el b/ivy.el
index c812466..744abc7 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1233,8 +1233,9 @@ CANDS is a list of strings."
(let* ((half-height (/ ivy-height 2))
(start (max 0 (- ivy--index half-height)))
(end (min (+ start (1- ivy-height)) ivy--length))
+ (start (max 0 (min start (- end (1- ivy-height)))))
(cands (cl-subseq cands start end))
- (index (min ivy--index half-height (1- (length cands)))))
+ (index (- ivy--index start)))
(when ivy--directory
(setq cands (mapcar (lambda (x)
(if (string-match-p "/\\'" x)