Skip to content

Commit 0c20bad

Browse files
committed
Handle when no candidates.
1 parent bccbf4a commit 0c20bad

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

ivy-file-preview.el

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,21 @@
106106

107107
;;; Core
108108

109+
(defun ivy-file-preview--candidates ()
110+
"Return current ivy candidates."
111+
(or ivy--old-cands ivy--all-candidates '()))
112+
113+
(defun ivy-file-preview--no-candidates-p ()
114+
"Return nil if there is no candidate in current ivy session."
115+
(>= 0 (length (ivy-file-preview--candidates))))
116+
109117
(defun ivy-file-preview--extract-candidates-overlay-data ()
110118
"Extract the overlay data from current ivy candidates."
111119
(let* ((project-dir (ivy-file-preview--project-path))
112120
(fn (if project-dir
113121
(s-replace project-dir "" ivy-file-preview--selected-file)
114122
ivy-file-preview--selected-file))
115-
(cands (or ivy--old-cands ivy--all-candidates '()))
123+
(cands (ivy-file-preview--candidates))
116124
(cands-len (length cands)) current-cand entered ln-data
117125
ln col
118126
cand-fn (results '()) break (index 0))
@@ -175,12 +183,12 @@ POS can either be an integer or cons cell represent line number and columns."
175183

176184
(defun ivy-file-preview--after-select (&rest _)
177185
"Execution after selection."
178-
(if (string-empty-p ivy-text)
186+
(if (or (string-empty-p ivy-text) (ivy-file-preview--no-candidates-p))
179187
(progn
180188
(ivy-file-preview--delete-overlays)
181189
(ivy-file-preview--back-to-pos))
182190
(let* ((project-dir (ivy-file-preview--project-path))
183-
(cands (or ivy--old-cands ivy--all-candidates '()))
191+
(cands (ivy-file-preview--candidates))
184192
(current-selection (or (nth ivy--index cands) ""))
185193
(sel-lst (split-string current-selection ":"))
186194
fn ln cl)

0 commit comments

Comments
 (0)