* counsel.el (counsel--async-sentinel): Rely on
`ivy-recompute-index-swiper-async' even when `ivy--old-cands' is nil.
* ivy.el (ivy--recompute-index): Check for `ivy--old-cands' being nil
before trying to index it.
(ivy-recompute-index-swiper-async): When `ivy--old-cands' is nil, look
for a string that's closest to the line number at point.
(ivy--set-candidates
(ivy--sort-maybe
cands))
(ivy--set-candidates
(ivy--sort-maybe
cands))
- (if (null ivy--old-cands)
- (setq ivy--index
- (or (ivy--preselect-index
- (ivy-state-preselect ivy-last)
- ivy--all-candidates)
- 0))
- (let ((re (funcall ivy--regex-function ivy-text)))
- (unless (stringp re)
- (setq re (caar re)))
+ (let ((re (funcall ivy--regex-function ivy-text)))
+ (unless (stringp re)
+ (setq re (caar re)))
+ (if (null ivy--old-cands)
+ (unless (setq ivy--index (ivy--preselect-index
+ (ivy-state-preselect ivy-last)
+ ivy--all-candidates))
+ (ivy--recompute-index
+ ivy-text re ivy--all-candidates))
(ivy--recompute-index
ivy-text re ivy--all-candidates)))
(setq ivy--old-cands ivy--all-candidates)
(ivy--recompute-index
ivy-text re ivy--all-candidates)))
(setq ivy--old-cands ivy--all-candidates)
(not (and (require 'flx nil 'noerror)
(eq ivy--regex-function 'ivy--regex-fuzzy)
(< (length cands) 200)))
(not (and (require 'flx nil 'noerror)
(eq ivy--regex-function 'ivy--regex-fuzzy)
(< (length cands) 200)))
(cl-position (nth ivy--index ivy--old-cands)
cands))
(funcall func re-str cands))))
(cl-position (nth ivy--index ivy--old-cands)
cands))
(funcall func re-str cands))))
res)))))
(defun ivy-recompute-index-swiper-async (_re-str cands)
res)))))
(defun ivy-recompute-index-swiper-async (_re-str cands)
- (let ((tail (nthcdr ivy--index ivy--old-cands))
- idx)
- (if (and tail ivy--old-cands (not (equal "^" ivy--old-re)))
- (progn
- (while (and tail (null idx))
- ;; Compare with `equal', since the collection is re-created
- ;; each time with `split-string'
- (setq idx (cl-position (pop tail) cands :test #'equal)))
- (or idx 0))
- ivy--index)))
+ (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))
+ (let ((tail (nthcdr ivy--index ivy--old-cands))
+ idx)
+ (if (and tail ivy--old-cands (not (equal "^" ivy--old-re)))
+ (progn
+ (while (and tail (null idx))
+ ;; Compare with `equal', since the collection is re-created
+ ;; each time with `split-string'
+ (setq idx (cl-position (pop tail) cands :test #'equal)))
+ (or idx 0))
+ ivy--index))))
(defun ivy-recompute-index-zero (_re-str _cands)
0)
(defun ivy-recompute-index-zero (_re-str _cands)
0)