* 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.
(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)))