Skip to content

Commit f76b834

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

8 files changed

Lines changed: 32 additions & 8 deletions

lua/fzf-lua/path.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,19 @@ function M.entry_to_file(entry, opts, force_uri)
528528
end
529529
end
530530
end
531+
local bufname
531532
local terminal
532533
if bufnr then
533534
terminal = utils.is_term_buffer(bufnr)
534535
if terminal then
535536
file, line = stripped:match("([^:]+):(%d+)")
536537
end
538+
elseif file and #file > 0 then -- get bufnr from give path
539+
local buf = vim.fn.bufnr(file)
540+
if buf ~= -1 and vim.api.nvim_buf_get_name(buf) == file then
541+
bufnr = buf
542+
bufname = file
543+
end
537544
end
538545
if opts.path_shorten and not M.is_uri(stripped) then
539546
file = M.lengthen(file)
@@ -542,8 +549,8 @@ function M.entry_to_file(entry, opts, force_uri)
542549
return {
543550
stripped = stripped,
544551
bufnr = bufnr,
545-
bufname = bufnr and vim.api.nvim_buf_is_valid(bufnr)
546-
and vim.api.nvim_buf_get_name(bufnr),
552+
bufname = bufname or (bufnr and vim.api.nvim_buf_is_valid(bufnr)
553+
and vim.api.nvim_buf_get_name(bufnr) or nil),
547554
terminal = terminal,
548555
path = file,
549556
line = utils.tointeger(type(opts.line_query) == "function" and

tests/path_spec.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,5 +464,22 @@ 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+
helpers.SKIP_IF_MAC()
470+
if helpers.IS_WIN() then helpers.SKIP_IF_NOT_NIGHTLY() end
471+
local r = {}
472+
vim.cmd [[bwipe]]
473+
vim.cmd.edit("/tmp/foo:bar.txt")
474+
local bufname = "/tmp/foo:bar.txt"
475+
eq(path.entry_to_file("/tmp/foo:bar.txt", r), {
476+
col = 0,
477+
line = 0,
478+
stripped = bufname,
479+
path = bufname,
480+
bufnr = vim.fn.bufnr(),
481+
bufname = helpers.IS_MAC() and vim.fs.joinpath("/private", bufname) or bufname,
482+
})
483+
end)
467484
end)
468485
end)

tests/screenshots/tests-actions_spec.lua---actions---vimcmd---1-+-args-{-'drop'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
12|d/or se│ │
1414
13|copies │ │Softwa
1515
14|re is ╰─────────────────────────────────────────────────╯
16-
15|furnish╭──────────────────── LICENSE ────────────────────╮
16+
15|furnish╭──────────────── buf 1: LICENSE ─────────────────╮
1717
16| │ 1 MIT License
1818
17|The abo│ 2 l be i
1919
18|ncluded│ 3 Copyright (c) 2021 iBhagwan │

tests/screenshots/tests-actions_spec.lua---actions---vimcmd---1-+-args-{-'file_edit'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
12|d/or se│ │
1414
13|copies │ │Softwa
1515
14|re is ╰─────────────────────────────────────────────────╯
16-
15|furnish╭──────────────────── LICENSE ────────────────────╮
16+
15|furnish╭──────────────── buf 6: LICENSE ─────────────────╮
1717
16| │ 1 MIT License
1818
17|The abo│ 2 l be i
1919
18|ncluded│ 3 Copyright (c) 2021 iBhagwan │

tests/screenshots/tests-actions_spec.lua---actions---vimcmd---1-+-args-{-'file_open_in_background'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
12|~ │ │
1414
13|~ │ │
1515
14|~ ╰─────────────────────────────────────────────────╯
16-
15|~ ╭──────────────────── LICENSE ────────────────────╮
16+
15|~ ╭──────────────── buf 6: LICENSE ─────────────────╮
1717
16|~ │ 1 MIT License
1818
17|~ │ 2
1919
18|~ │ 3 Copyright (c) 2021 iBhagwan │

tests/screenshots/tests-actions_spec.lua---actions---vimcmd---1-+-args-{-'file_split'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
12|LICENSE│ │ Top
1414
13| │ │
1515
14|~ ╰─────────────────────────────────────────────────╯
16-
15|~ ╭──────────────────── LICENSE ────────────────────╮
16+
15|~ ╭──────────────── buf 6: LICENSE ─────────────────╮
1717
16|~ │ 1 MIT License
1818
17|~ │ 2
1919
18|~ │ 3 Copyright (c) 2021 iBhagwan │

tests/screenshots/tests-actions_spec.lua---actions---vimcmd---1-+-args-{-'file_tabedit'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
12|to use,│ │se, an
1414
13|d/or se│ │
1515
14|copies ╰─────────────────────────────────────────────────╯Softwa
16-
15|re is ╭──────────────────── LICENSE ────────────────────╮
16+
15|re is ╭──────────────── buf 7: LICENSE ─────────────────╮
1717
16|furnish│ 1 MIT License
1818
17| │ 2
1919
18|The abo│ 3 Copyright (c) 2021 iBhagwan │l be i

tests/screenshots/tests-actions_spec.lua---actions---vimcmd---1-+-args-{-'file_vsplit'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
12|ion, in│ │
1414
13|n the r│ │
1515
14|to use,╰─────────────────────────────────────────────────╯
16-
15|lish, d╭──────────────────── LICENSE ────────────────────╮
16+
15|lish, d╭──────────────── buf 6: LICENSE ─────────────────╮
1717
16|d/or se│ 1 MIT License
1818
17|copies │ 2
1919
18|ermit p│ 3 Copyright (c) 2021 iBhagwan │

0 commit comments

Comments
 (0)