fix(builtin.buffers): previews with specified cwd option (#3111)

Currently, the buffer name is normalized to the `cwd` option value.
This buffer name is then used as the filename, which is used as the file
path for the previewer. But if the `cwd` value is not the actual cwd,
the buffer path can no longer be found by the previewer (relative to the
true cwd).

This is fixed by adding a `path` value to the entry that's the full path
of the buffer. The previewer will then use this full path to find the
file to preview.

(cherry picked from commit ccaeeb5af5)
This commit is contained in:
James Trew
2024-05-16 22:55:28 -04:00
committed by Simon Hauser
parent 9194becd77
commit 2e5f7ae754
+3 -4
View File
@@ -615,9 +615,8 @@ function make_entry.gen_from_buffer(opts)
end
return function(entry)
local bufname = entry.info.name ~= "" and entry.info.name or "[No Name]"
-- if bufname is inside the cwd, trim that part of the string
bufname = Path:new(bufname):normalize(cwd)
local filename = entry.info.name ~= "" and entry.info.name or nil
local bufname = filename and Path:new(filename):normalize(cwd) or "[No Name]"
local hidden = entry.info.hidden == 1 and "h" or "a"
local readonly = vim.api.nvim_buf_get_option(entry.bufnr, "readonly") and "=" or " "
@@ -640,8 +639,8 @@ function make_entry.gen_from_buffer(opts)
value = bufname,
ordinal = entry.bufnr .. " : " .. bufname,
display = make_display,
bufnr = entry.bufnr,
path = filename,
filename = bufname,
lnum = lnum,
indicator = indicator,