emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 6f56049 230/399: ivy.el (ivy--minibuffer-index-bounds): Ma


From: Oleh Krehel
Subject: [elpa] master 6f56049 230/399: ivy.el (ivy--minibuffer-index-bounds): Make pure
Date: Sat, 20 Jul 2019 14:57:29 -0400 (EDT)

branch: master
commit 6f56049dc3b53e25d151f301b42c3b2e7f71d269
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    ivy.el (ivy--minibuffer-index-bounds): Make pure
    
    * ivy-test.el (ivy--minibuffer-index-bounds): Add test.
---
 ivy-test.el | 12 ++++++++++++
 ivy.el      | 19 ++++++++++---------
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/ivy-test.el b/ivy-test.el
index 46a72dd..ff76dcb 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -1120,6 +1120,18 @@ a buffer visiting a file."
                                "C-p C-m")
                      ""))))
 
+(ert-deftest ivy--minibuffer-index-bounds ()
+  (should (equal (ivy--minibuffer-index-bounds 0 1 10) '(0 1 0)))
+  (should (equal (ivy--minibuffer-index-bounds 0 10 10) '(0 9 0)))
+  (should (equal (ivy--minibuffer-index-bounds 0 11 10) '(0 9 0)))
+  (should (equal (ivy--minibuffer-index-bounds 1 11 10) '(0 9 1)))
+  (should (equal (ivy--minibuffer-index-bounds 5 11 10) '(0 9 5)))
+  (should (equal (ivy--minibuffer-index-bounds 6 11 10) '(1 10 5)))
+  (should (equal (ivy--minibuffer-index-bounds 7 11 10) '(2 11 5)))
+  (should (equal (ivy--minibuffer-index-bounds 8 11 10) '(2 11 6)))
+  (should (equal (ivy--minibuffer-index-bounds 10 11 10) '(2 11 8)))
+  (should (equal (ivy--minibuffer-index-bounds 1 3 10) '(0 3 1))))
+
 (defun counsel--setup-test-files ()
   (unless (file-exists-p "tests/")
     (shell-command
diff --git a/ivy.el b/ivy.el
index ea23797..c5aecb9 100644
--- a/ivy.el
+++ b/ivy.el
@@ -3595,14 +3595,13 @@ Note: The usual last two arguments are flipped for 
convenience.")
       (propertize str 'face 'ivy-subdir)
     str))
 
-(defun ivy--minibuffer-index-bounds ()
-  (let* ((half-height (/ ivy-height 2))
+(defun ivy--minibuffer-index-bounds (idx len wnd-len)
+  (let* ((half-height (/ wnd-len 2))
          (start (max 0
-                     (min (- ivy--index half-height)
-                          (- ivy--length (1- ivy-height)))))
-         (end (min (+ start (1- ivy-height)) ivy--length)))
-    (setq ivy--window-index (- ivy--index start))
-    (cons start end)))
+                     (min (- idx half-height)
+                          (- len (1- wnd-len)))))
+         (end (min (+ start (1- wnd-len)) len)))
+    (list start end (- idx start))))
 
 (defun ivy--format (cands)
   "Return a string for CANDS suitable for display in the minibuffer.
@@ -3613,9 +3612,11 @@ CANDS is a list of strings."
   (if (null cands)
       (setf (ivy-state-current ivy-last) "")
     (setf (ivy-state-current ivy-last) (copy-sequence (nth ivy--index cands)))
-    (let* ((bnd (ivy--minibuffer-index-bounds))
-           (wnd-cands (cl-subseq cands (car bnd) (cdr bnd)))
+    (let* ((bnd (ivy--minibuffer-index-bounds
+                 ivy--index ivy--length ivy-height))
+           (wnd-cands (cl-subseq cands (car bnd) (cadr bnd)))
            transformer-fn)
+      (setq ivy--window-index (nth 2 bnd))
       (when (setq transformer-fn (ivy-state-display-transformer-fn ivy-last))
         (with-ivy-window
           (with-current-buffer (ivy-state-buffer ivy-last)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]