@@ -91,12 +91,31 @@ It could either by `project-directory' or `default-directory'")
91
91
(defvar ivy-file-preview--this-command nil
92
92
" Record of this command when entering minibuffer." )
93
93
94
+ (defvar ivy-file-preview--first-cand-index nil
95
+ " Record of first candidate's index." )
96
+
94
97
; ;; External
95
98
96
99
(defvar ivy-searcher--candidates )
97
100
98
101
; ;; Util
99
102
103
+ (defun ivy-file-preview--ivy-searcher-p ()
104
+ " Return non-nil if current command is from `ivy-searcher' ."
105
+ (memq ivy-file-preview--this-command '(ivy-searcher-search-file
106
+ ivy-searcher-search-project)))
107
+
108
+ (defun ivy-file-preview--filter-candidates ()
109
+ " Filter possible candidates for overlays."
110
+ (when (ivy-file-preview--ivy-searcher-p)
111
+ (setq ivy-file-preview--first-cand-index
112
+ (cl-position
113
+ nil ivy-searcher--candidates
114
+ :test
115
+ (lambda (_key cand )
116
+ (pop cand)
117
+ (string= ivy-file-preview--selected-file (plist-get cand :file )))))))
118
+
100
119
(defun ivy-file-preview--match-end (&optional pos index )
101
120
" Get matching end by currently selected candidate.
102
121
@@ -105,9 +124,11 @@ length of `ivy-text'.
105
124
106
125
An optional argument INDEX is use to find current ivy candidate."
107
126
(unless pos (setq pos (point )))
108
- (unless index (setq index ivy--index))
109
- (cond ((memq ivy-file-preview--this-command '(ivy-searcher-search-file
110
- ivy-searcher-search-project))
127
+ (if index
128
+ (when ivy-file-preview--first-cand-index
129
+ (setq index (+ index ivy-file-preview--first-cand-index)))
130
+ (setq index ivy--index))
131
+ (cond ((ivy-file-preview--ivy-searcher-p)
111
132
(let* ((cand (nth index ivy-searcher--candidates))
112
133
(plist-data (cdr cand))
113
134
(end-pt (plist-get plist-data :end )))
@@ -183,15 +204,16 @@ If CURRENT-OV is non-nil it create overlay that are currently selected."
183
204
184
205
(defun ivy-file-preview--extract-candidates-overlay-data ()
185
206
" Extract the overlay data from current ivy candidates."
207
+ (ivy-file-preview--filter-candidates)
186
208
(let* ((fn (s-replace ivy-file-preview--current-dir " " ivy-file-preview--selected-file))
187
209
(cands (ivy-file-preview--candidates))
188
210
(cands-len (length cands)) current-cand entered ln-data
189
211
ln col
190
212
cand-fn (results '()) break (index 0 ))
191
213
(while (and (not break) (< index cands-len))
192
- (setq current-cand (nth index cands))
193
- ( setq ln-data (split-string current-cand " :" ) )
194
- ( setq cand-fn (nth 0 ln-data))
214
+ (setq current-cand (nth index cands)
215
+ ln-data (split-string current-cand " :" )
216
+ cand-fn (nth 0 ln-data))
195
217
(if (string= cand-fn fn)
196
218
(progn
197
219
(setq ln (nth 1 ln-data) col (nth 2 ln-data))
0 commit comments