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

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

[elpa] externals/swiper a5eade0 2/3: Fix swiper-avy indexing in swiper-i


From: Basil L. Contovounesios
Subject: [elpa] externals/swiper a5eade0 2/3: Fix swiper-avy indexing in swiper-isearch (#2873)
Date: Fri, 21 May 2021 09:22:23 -0400 (EDT)

branch: externals/swiper
commit a5eade0c77b7dd78cdea0f246683c6cb00f7b7c6
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>

    Fix swiper-avy indexing in swiper-isearch (#2873)
    
    * swiper.el (swiper--avy-index): New function extracted from
    swiper--avy-goto that additionally checks for the 'point' text
    property used by swiper-isearch (#2867).
    (swiper--avy-goto): Use it.  Set ivy--index directly instead of
    going through ivy-set-index as the latter heeds ivy-calling.
---
 swiper.el | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/swiper.el b/swiper.el
index ed8192d..fe4fbb7 100644
--- a/swiper.el
+++ b/swiper.el
@@ -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))



reply via email to

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