Skip to content

Commit 72af3f8

Browse files
committed
fix(preview): parse bufnr from loaded path
1 parent f6ebde2 commit 72af3f8

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

lua/fzf-lua/path.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,11 @@ function M.entry_to_file(entry, opts, force_uri)
534534
if terminal then
535535
file, line = stripped:match("([^:]+):(%d+)")
536536
end
537+
elseif file and #file > 0 then -- get bufnr from give path
538+
local buf = vim.fn.bufnr(file)
539+
if buf ~= -1 and vim.api.nvim_buf_get_name(buf) == file then
540+
bufnr = buf
541+
end
537542
end
538543
if opts.path_shorten and not M.is_uri(stripped) then
539544
file = M.lengthen(file)

tests/path_spec.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,5 +464,21 @@ describe("Testing path module", function()
464464
eq(path.entry_to_file("file:///tmp/test.txt:5:6", {}, false), r)
465465
eq(path.entry_to_file("file:///tmp/test.txt:5:6", {}, true), r)
466466
end)
467+
468+
it("parse loaded path", function()
469+
if helpers.IS_WIN() then helpers.SKIP_IF_NOT_NIGHTLY() end
470+
local r = {}
471+
vim.cmd [[bwipe]]
472+
vim.cmd.edit("/tmp/foo:bar.txt")
473+
local bufname = "/tmp/foo:bar.txt"
474+
eq(path.entry_to_file("/tmp/foo:bar.txt", r), {
475+
col = 0,
476+
line = 0,
477+
stripped = bufname,
478+
path = bufname,
479+
bufnr = vim.fn.bufnr(),
480+
bufname = helpers.IS_MAC() and vim.fs.joinpath("/private", bufname) or bufname,
481+
})
482+
end)
467483
end)
468484
end)

0 commit comments

Comments
 (0)