|
106 | 106 |
|
107 | 107 | ;;; Core |
108 | 108 |
|
| 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 | + |
109 | 117 | (defun ivy-file-preview--extract-candidates-overlay-data () |
110 | 118 | "Extract the overlay data from current ivy candidates." |
111 | 119 | (let* ((project-dir (ivy-file-preview--project-path)) |
112 | 120 | (fn (if project-dir |
113 | 121 | (s-replace project-dir "" ivy-file-preview--selected-file) |
114 | 122 | ivy-file-preview--selected-file)) |
115 | | - (cands (or ivy--old-cands ivy--all-candidates '())) |
| 123 | + (cands (ivy-file-preview--candidates)) |
116 | 124 | (cands-len (length cands)) current-cand entered ln-data |
117 | 125 | ln col |
118 | 126 | cand-fn (results '()) break (index 0)) |
@@ -175,12 +183,12 @@ POS can either be an integer or cons cell represent line number and columns." |
175 | 183 |
|
176 | 184 | (defun ivy-file-preview--after-select (&rest _) |
177 | 185 | "Execution after selection." |
178 | | - (if (string-empty-p ivy-text) |
| 186 | + (if (or (string-empty-p ivy-text) (ivy-file-preview--no-candidates-p)) |
179 | 187 | (progn |
180 | 188 | (ivy-file-preview--delete-overlays) |
181 | 189 | (ivy-file-preview--back-to-pos)) |
182 | 190 | (let* ((project-dir (ivy-file-preview--project-path)) |
183 | | - (cands (or ivy--old-cands ivy--all-candidates '())) |
| 191 | + (cands (ivy-file-preview--candidates)) |
184 | 192 | (current-selection (or (nth ivy--index cands) "")) |
185 | 193 | (sel-lst (split-string current-selection ":")) |
186 | 194 | fn ln cl) |
|
0 commit comments