From 341b5a239f14cb9b385db32567edb1e792930c08 Mon Sep 17 00:00:00 2001 From: Oleh Krehel Date: Wed, 6 Apr 2016 19:36:41 +0200 Subject: [PATCH] counsel-grep should pick candidates closest to point * ivy.el (ivy-recompute-index-swiper-async): Update. Fixes the algorithm selecting the first matching candidate in case there are 0 matching candidates following point. Now the last matching candidate will be selected, resulting in less scrolling. --- ivy.el | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ivy.el b/ivy.el index 415f54a68..16e7d7fce 100644 --- a/ivy.el +++ b/ivy.el @@ -2242,10 +2242,13 @@ Prefix matches to NAME are put ahead of the list." (if (null ivy--old-cands) (let ((ln (with-ivy-window (line-number-at-pos)))) - (or (cl-position-if (lambda (x) - (>= (string-to-number x) ln)) - cands) - 0)) + (or + ;; closest to current line going forwards + (cl-position-if (lambda (x) + (>= (string-to-number x) ln)) + cands) + ;; closest to current line going backwards + (1- (length cands)))) (let ((tail (nthcdr ivy--index ivy--old-cands)) idx) (if (and tail ivy--old-cands (not (equal "^" ivy--old-re))) -- 2.39.2