@@ -170,17 +170,27 @@ POS can either be an integer or cons cell represent line number and columns."
170170
171171(defun ivy-file-preview--after-select (&rest _ )
172172 " Execution after selection."
173- (let* ((project-dir (ivy-file-preview--project-path))
174- (cands (or ivy--old-cands ivy--all-candidates '()))
175- (current-selection (or (nth ivy--index cands) " " ))
176- (sel-lst (split-string current-selection " :" ))
177- fn ln cl)
178- (when (< 2 (length sel-lst))
179- (setq fn (nth 0 sel-lst) ln (nth 1 sel-lst) cl (nth 2 sel-lst)))
180- (when (and ivy-file-preview-details ln)
181- (setq ln (string-to-number ln)
182- cl (ignore-errors (cl-parse-integer cl)))
183- (ivy-file-preview--do-preview project-dir fn (if cl (cons ln cl) ln)))))
173+ (if (string-empty-p ivy-text)
174+ (progn
175+ (ivy-file-preview--delete-overlays)
176+ (ivy-file-preview--back-to-pos))
177+ (let* ((project-dir (ivy-file-preview--project-path))
178+ (cands (or ivy--old-cands ivy--all-candidates '()))
179+ (current-selection (or (nth ivy--index cands) " " ))
180+ (sel-lst (split-string current-selection " :" ))
181+ fn ln cl)
182+ (when (< 2 (length sel-lst))
183+ (setq fn (nth 0 sel-lst) ln (nth 1 sel-lst) cl (nth 2 sel-lst)))
184+ (when (and ivy-file-preview-details ln)
185+ (setq ln (string-to-number ln)
186+ cl (ignore-errors (cl-parse-integer cl)))
187+ (ivy-file-preview--do-preview project-dir fn (if cl (cons ln cl) ln))))))
188+
189+ (defun ivy-file-preview--back-to-pos ()
190+ " Back to starting position."
191+ (with-selected-window minibuffer-scroll-window
192+ (switch-to-buffer (nth 0 ivy-file-preview--window-status))
193+ (goto-char (nth 2 ivy-file-preview--window-status))))
184194
185195(defun ivy-file-preview--cancel-revert ()
186196 " Revert frame status if user cancel the commands."
@@ -194,6 +204,7 @@ POS can either be an integer or cons cell represent line number and columns."
194204 " Execution after minibuffer setup."
195205 (setq ivy-file-preview--window-status '())
196206 (with-selected-window minibuffer-scroll-window
207+ (push (point ) ivy-file-preview--window-status)
197208 (push (window-point ) ivy-file-preview--window-status)
198209 (push (buffer-name ) ivy-file-preview--window-status)))
199210
0 commit comments