Skip to content

Commit

Permalink
Fix swiper-avy indexing in swiper-isearch (abo-abo#2873)
Browse files Browse the repository at this point in the history
* swiper.el (swiper--avy-index): New function extracted from
swiper--avy-goto that additionally checks for the 'point' text
property used by swiper-isearch (abo-abo#2867).
(swiper--avy-goto): Use it.  Set ivy--index directly instead of
going through ivy-set-index as the latter heeds ivy-calling.
  • Loading branch information
basil-conto committed May 21, 2021
1 parent f6b46bc commit a5eade0
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions swiper.el
Original file line number Diff line number Diff line change
Expand Up @@ -332,19 +332,28 @@ If the input is empty, select the previous history element instead."
(avy-push-mark))
(avy--done))))

(defun swiper--avy-index (pos)
"Return `ivy--index' for `avy' candidate at minibuffer POS."
;; Position in original buffer.
(let ((opos (get-text-property pos 'point)))
(or
;; Find `swiper-isearch' index based on buffer position.
(and opos (cl-position opos ivy--all-candidates))
;; Find `swiper' index based on line number.
(let ((nlines (count-lines (point-min) (point-max))))
(+ (car (ivy--minibuffer-index-bounds
ivy--index ivy--length ivy-height))
(line-number-at-pos pos)
(if (or (= nlines (1+ ivy-height))
(< ivy--length ivy-height))
0
(- ivy-height nlines))
-2)))))

(defun swiper--avy-goto (candidate)
(cond ((let ((win (cdr-safe candidate)))
(and win (window-minibuffer-p win)))
(let ((nlines (count-lines (point-min) (point-max))))
(ivy-set-index
(+ (car (ivy--minibuffer-index-bounds
ivy--index ivy--length ivy-height))
(line-number-at-pos (car candidate))
(if (or (= nlines (1+ ivy-height))
(< ivy--length ivy-height))
0
(- ivy-height nlines))
-2)))
(setq ivy--index (swiper--avy-index (car candidate)))
(ivy--exhibit)
(ivy-done)
(ivy-call))
Expand Down

0 comments on commit a5eade0

Please sign in to comment.