From 8313277e0bb206ddf76a23265b4a71cf3cacf568 Mon Sep 17 00:00:00 2001 From: Mark Oborne Date: Sun, 5 Jun 2022 15:17:08 +0100 Subject: [PATCH] fix(jumps): fix preview not showing correctly Fixes two issues: * Preview wasn't showing the jump location when the file was outside of the pwd. * Preview wasn't showing the jump location when the jump was on a blank line in the current buffer. --- lua/fzf-lua/previewer/builtin.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lua/fzf-lua/previewer/builtin.lua b/lua/fzf-lua/previewer/builtin.lua index 9ae9e69..9d136c2 100644 --- a/lua/fzf-lua/previewer/builtin.lua +++ b/lua/fzf-lua/previewer/builtin.lua @@ -839,11 +839,17 @@ end function Previewer.jumps:parse_entry(entry_str) local bufnr = nil local _, lnum, col, filepath = entry_str:match("(%d+)%s+(%d+)%s+(%d+)%s+(.*)") - if filepath and #filepath>0 and not vim.loop.fs_stat(filepath) then - -- file is not accessible, - -- text is a string from current buffer - bufnr = self.win.src_bufnr - filepath = vim.api.nvim_buf_get_name(self.win.src_bufnr) + if filepath then + local ok, res = pcall(vim.fn.expand, filepath) + if ok then + filepath = path.relative(res, vim.loop.cwd()) + end + if not vim.loop.fs_stat(filepath) then + -- file is not accessible, + -- text is a string from current buffer + bufnr = self.win.src_bufnr + filepath = vim.api.nvim_buf_get_name(self.win.src_bufnr) + end end return { bufnr = bufnr,