Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lua/fzf-lua/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,19 @@ function M.entry_to_file(entry, opts, force_uri)
end
end
end
local bufname
local terminal
if bufnr then
terminal = utils.is_term_buffer(bufnr)
if terminal then
file, line = stripped:match("([^:]+):(%d+)")
end
elseif file and #file > 0 then -- get bufnr from give path
local buf = vim.fn.bufnr(file)
if buf ~= -1 and vim.api.nvim_buf_get_name(buf) == file then
bufnr = buf
bufname = file
end
end
if opts.path_shorten and not M.is_uri(stripped) then
file = M.lengthen(file)
Expand All @@ -542,8 +549,8 @@ function M.entry_to_file(entry, opts, force_uri)
return {
stripped = stripped,
bufnr = bufnr,
bufname = bufnr and vim.api.nvim_buf_is_valid(bufnr)
and vim.api.nvim_buf_get_name(bufnr),
bufname = bufname or (bufnr and vim.api.nvim_buf_is_valid(bufnr)
and vim.api.nvim_buf_get_name(bufnr) or nil),
terminal = terminal,
path = file,
line = utils.tointeger(type(opts.line_query) == "function" and
Expand Down
26 changes: 13 additions & 13 deletions lua/fzf-lua/previewer/builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -615,17 +615,15 @@ function Previewer.base:copy_extmarks()
local win = self.win.preview_winid
local topline = fn.line("w0", win)
local botline = fn.line("w$", win)
api.nvim_buf_clear_namespace(dst_bufnr, ns, topline, botline)
for _, n in pairs(api.nvim_get_namespaces()) do
local extmarks = api.nvim_buf_get_extmarks(src_bufnr, n, { topline - 1, 0 },
{ botline - 1, -1 },
{ details = true })
for _, m in ipairs(extmarks) do
local _, row, col, details = unpack(m) ---@cast details -?
local endRow, endCol = details.end_row, details.end_col
local hlGroup = details.hl_group
local priority = details.priority
pcall(api.nvim_buf_set_extmark, dst_bufnr, ns, row, col,
{ end_row = endRow, end_col = endCol, hl_group = hlGroup, priority = priority })
details.ns_id = nil
pcall(api.nvim_buf_set_extmark, dst_bufnr, ns, row, col, details)
end
end
end
Expand Down Expand Up @@ -688,16 +686,17 @@ function Previewer.buffer_or_file:parse_entry(entry_str, _cb)
-- filename only
if buf and api.nvim_buf_is_valid(buf) then
entry.path = path.relative_to(api.nvim_buf_get_name(buf), utils.cwd())
end
if entry.path then
if entry.path:find("^fugitive://") and buf and api.nvim_buf_is_valid(buf) then
if fn.exists("#fugitive#BufReadCmd") == 1 then
api.nvim_buf_call(buf, function()
api.nvim_exec_autocmds("BufReadCmd", { group = "fugitive", pattern = entry.path })
end)
end
if entry.path:find("^fugitive://") then
api.nvim_buf_call(buf, function()
api.nvim_exec_autocmds("BufReadCmd", {
group = fn.exists("#fugitive#BufReadCmd") == 1 and "fugitive" or nil,
pattern = entry.path
})
end)
return entry
end
end
if entry.path then
entry.tick = vim.tbl_get(uv.fs_stat(entry.path) or {}, "mtime", "nsec")
end
return entry
Expand Down Expand Up @@ -1451,6 +1450,7 @@ function Previewer.buffer_or_file:preview_buf_post(entry, min_winopts)
self:update_render_markdown()
self:update_ts_context()
self:attach_snacks_image_inline()
vim.schedule(function() self:copy_extmarks() end)
end
-- for attach_snacks_image_{inline,buf}
-- https://github.com/folke/snacks.nvim/pull/1615
Expand Down
17 changes: 17 additions & 0 deletions tests/path_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -464,5 +464,22 @@ describe("Testing path module", function()
eq(path.entry_to_file("file:///tmp/test.txt:5:6", {}, false), r)
eq(path.entry_to_file("file:///tmp/test.txt:5:6", {}, true), r)
end)

it("parse loaded path", function()
helpers.SKIP_IF_MAC()
if helpers.IS_WIN() then helpers.SKIP_IF_NOT_NIGHTLY() end
local r = {}
vim.cmd [[bwipe]]
vim.cmd.edit("/tmp/foo:bar.txt")
local bufname = "/tmp/foo:bar.txt"
eq(path.entry_to_file("/tmp/foo:bar.txt", r), {
col = 0,
line = 0,
stripped = bufname,
path = bufname,
bufnr = vim.fn.bufnr(),
bufname = helpers.IS_MAC() and vim.fs.joinpath("/private", bufname) or bufname,
})
end)
end)
end)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
12|d/or se│ │
13|copies │ │Softwa
14|re is ╰─────────────────────────────────────────────────╯
15|furnish╭──────────────────── LICENSE ────────────────────╮
15|furnish╭──────────────── buf 1: LICENSE ─────────────────╮
16| │ 1 MIT License
17|The abo│ 2 l be i
18|ncluded│ 3 Copyright (c) 2021 iBhagwan │
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
12|d/or se│ │
13|copies │ │Softwa
14|re is ╰─────────────────────────────────────────────────╯
15|furnish╭──────────────────── LICENSE ────────────────────╮
15|furnish╭──────────────── buf 6: LICENSE ─────────────────╮
16| │ 1 MIT License
17|The abo│ 2 l be i
18|ncluded│ 3 Copyright (c) 2021 iBhagwan │
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
12|~ │ │
13|~ │ │
14|~ ╰─────────────────────────────────────────────────╯
15|~ ╭──────────────────── LICENSE ────────────────────╮
15|~ ╭──────────────── buf 6: LICENSE ─────────────────╮
16|~ │ 1 MIT License
17|~ │ 2
18|~ │ 3 Copyright (c) 2021 iBhagwan │
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
12|LICENSE│ │ Top
13| │ │
14|~ ╰─────────────────────────────────────────────────╯
15|~ ╭──────────────────── LICENSE ────────────────────╮
15|~ ╭──────────────── buf 6: LICENSE ─────────────────╮
16|~ │ 1 MIT License
17|~ │ 2
18|~ │ 3 Copyright (c) 2021 iBhagwan │
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
12|to use,│ │se, an
13|d/or se│ │
14|copies ╰─────────────────────────────────────────────────╯Softwa
15|re is ╭──────────────────── LICENSE ────────────────────╮
15|re is ╭──────────────── buf 7: LICENSE ─────────────────╮
16|furnish│ 1 MIT License
17| │ 2
18|The abo│ 3 Copyright (c) 2021 iBhagwan │l be i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
12|ion, in│ │
13|n the r│ │
14|to use,╰─────────────────────────────────────────────────╯
15|lish, d╭──────────────────── LICENSE ────────────────────╮
15|lish, d╭──────────────── buf 6: LICENSE ─────────────────╮
16|d/or se│ 1 MIT License
17|copies │ 2
18|ermit p│ 3 Copyright (c) 2021 iBhagwan │
Expand Down