branch: master
commit 2191bdb41a0cc0f45c1f2710208d73b82e9e386e
Author: Oleh Krehel <ohwoeo...@gmail.com>
Commit: Oleh Krehel <ohwoeo...@gmail.com>

    ivy.el (ivy-completions): Simplify
---
 ivy.el |   19 ++++++-------------
 1 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/ivy.el b/ivy.el
index 25d8a70..34f7ad8 100644
--- a/ivy.el
+++ b/ivy.el
@@ -362,19 +362,12 @@ CANDIDATES is a list of strings."
       (setq ivy--index (max (1- ivy--length) 0)))
     (if (null cands)
         ""
-      (let ((index ivy--index))
-        (if (< index (/ ivy-height 2))
-            (setq cands
-                  (cl-subseq cands 0 (min (1- ivy-height) ivy--length)))
-          (setq cands
-                (cl-subseq cands
-                           (- index (/ ivy-height 2))
-                           (min (+ index (/ ivy-height 2))
-                                ivy--length)))
-          (setq index (min (/ ivy-height 2)
-                           (1- (length cands)))))
-        (setq ivy--current (copy-sequence
-                            (nth index cands)))
+      (let* ((half-height (/ ivy-height 2))
+             (start (max 0 (- ivy--index half-height)))
+             (end (min (+ start (1- ivy-height)) ivy--length))
+             (cands (cl-subseq cands start end))
+             (index (min ivy--index half-height (1- (length cands)))))
+        (setq ivy--current (copy-sequence (nth index cands)))
         (setf (nth index cands)
               (ivy--add-face ivy--current 'ivy-current-match))
         (concat "\n" (mapconcat

Reply via email to