Skip to content

Commit 7406433

Browse files
committed
Fixed file name issue
1 parent 402b4b9 commit 7406433

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

ivy-file-preview.el

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ An optional argument INDEX is use to find current ivy candidate."
189189

190190
(defun ivy-file-preview--convert-pos-delta (ln col)
191191
"Convert LN and COL to position point."
192-
(save-excursion
193-
(forward-line ln)
194-
(+ (point) col)))
192+
(save-excursion (forward-line ln) (+ (point) col)))
195193

196194
(defun ivy-file-preview--make-overlay (beg end &optional current-ov)
197195
"Make a new overlay with BEG, END and face (FC).
@@ -291,23 +289,25 @@ If CURRENT-OV is non-nil it create overlay that are currently selected."
291289
"Open the file path (FN) and move to POS.
292290
If POS is nil then it won't moves."
293291
(let ((is-fild-p t) (just-fn (f-filename fn)))
294-
(cond ((file-exists-p fn) (find-file fn))
292+
(cond ((file-exists-p fn)
293+
(setq ivy-file-preview--selected-file fn)
294+
(find-file fn))
295295
((not ivy-file-preview-details) (setq is-fild-p nil))
296296
((or (find-buffer-visiting fn) (get-buffer just-fn))
297+
(setq ivy-file-preview--selected-file just-fn)
297298
(switch-to-buffer just-fn))
298-
(t (setq is-fild-p nil)))
299-
(if (not is-fild-p)
300-
(setq ivy-file-preview--selected-file "")
301-
(setq ivy-file-preview--selected-file fn)
302-
(cond ((consp pos)
303-
(ivy-file-preview--goto-line (car pos))
304-
(move-to-column (cdr pos))
305-
(recenter))
306-
((integerp pos)
307-
(goto-char (1+ pos))
308-
(recenter))
309-
((not pos) (goto-char (point-min)))
310-
(t (error "Invalid position details: %s" pos))))
299+
(t
300+
(setq ivy-file-preview--selected-file ""
301+
is-fild-p nil)))
302+
(cond ((consp pos)
303+
(ivy-file-preview--goto-line (car pos))
304+
(move-to-column (cdr pos))
305+
(recenter))
306+
((integerp pos)
307+
(goto-char (1+ pos))
308+
(recenter))
309+
((not pos) (goto-char (point-min)))
310+
(t (error "Invalid position details: %s" pos)))
311311
is-fild-p))
312312

313313
(defun ivy-file-preview--do-preview (fn pos)
@@ -335,6 +335,18 @@ FN is the file path. POS can either be one of the following type:
335335
#'ivy-file-preview--delay-make-overlays)))
336336
(setq ivy-file-preview--ivy-text ivy-text)))))
337337

338+
(defun ivy-file-preview--read-selection (selection)
339+
"Read SELECTION and return list of data (file, line, column)."
340+
(let ((buf-lst (buffer-list)) buf-name buf-regex sel-lst)
341+
(cl-some (lambda (buf)
342+
(setq buf-name (buffer-name buf)
343+
buf-regex (format "^%s" (regexp-quote buf-name)))
344+
(string-match-p buf-regex selection))
345+
buf-lst)
346+
(setq selection (s-replace-regexp buf-regex "" selection)
347+
sel-lst (split-string selection ":"))
348+
(list buf-name (nth 1 sel-lst) (nth 2 sel-lst))))
349+
338350
(defun ivy-file-preview--after-select (&rest _)
339351
"Execution after selection."
340352
(if (and ivy-file-preview-details
@@ -344,7 +356,7 @@ FN is the file path. POS can either be one of the following type:
344356
(ivy-file-preview--back-to-pos))
345357
(let* ((cands (ivy-file-preview--candidates))
346358
(current-selection (or (nth ivy--index cands) ""))
347-
(sel-lst (split-string current-selection ":"))
359+
(sel-lst (ivy-file-preview--read-selection current-selection))
348360
(fn (nth 0 sel-lst)) (ln (nth 1 sel-lst)) (cl (nth 2 sel-lst))
349361
can-preview-p)
350362
(setq can-preview-p (if ivy-file-preview-details ln t))

0 commit comments

Comments
 (0)