fix: no longer leaking one buffer previewer in some occasions (#664)
* fix: stop leaking last preview buffer * fix: formatting for docs * fix: async check if file is dir or not and - fix for in_fast_event when overriding file_maker * fix: filtering for space in keymaps and fzy * fix: show correct result numbers when using file_ignore_patterns * Handle early close. Caused because we actually cleaning up buffers now * cleanup * [docgen] Update doc/telescope.txt
This commit is contained in:
@@ -66,28 +66,36 @@ previewers.file_maker = function(filepath, bufnr, opts)
|
||||
|
||||
if opts.bufname ~= filepath then
|
||||
if not vim.in_fast_event() then filepath = vim.fn.expand(filepath) end
|
||||
local stat = vim.loop.fs_stat(filepath) or {}
|
||||
if stat.type == 'directory' then
|
||||
pscan.ls_async(filepath, {
|
||||
hidden = true,
|
||||
group_directories_first = true,
|
||||
on_exit = vim.schedule_wrap(function(data, sections)
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, data)
|
||||
colorize_ls(bufnr, data, sections)
|
||||
if opts.callback then opts.callback(bufnr) end
|
||||
end)})
|
||||
else
|
||||
path.read_file_async(filepath, vim.schedule_wrap(function(data)
|
||||
if not vim.api.nvim_buf_is_valid(bufnr) then return end
|
||||
local ok = pcall(vim.api.nvim_buf_set_lines, bufnr, 0, -1, false, vim.split(data, '[\r]?\n'))
|
||||
if not ok then return end
|
||||
vim.loop.fs_stat(filepath, function(_, stat)
|
||||
if not stat then return end
|
||||
if stat.type == 'directory' then
|
||||
pscan.ls_async(filepath, {
|
||||
hidden = true,
|
||||
group_directories_first = true,
|
||||
on_exit = vim.schedule_wrap(function(data, sections)
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, data)
|
||||
colorize_ls(bufnr, data, sections)
|
||||
if opts.callback then opts.callback(bufnr) end
|
||||
end)})
|
||||
else
|
||||
path.read_file_async(filepath, vim.schedule_wrap(function(data)
|
||||
if not vim.api.nvim_buf_is_valid(bufnr) then return end
|
||||
local ok = pcall(vim.api.nvim_buf_set_lines, bufnr, 0, -1, false, vim.split(data, '[\r]?\n'))
|
||||
if not ok then return end
|
||||
|
||||
if opts.callback then opts.callback(bufnr) end
|
||||
putils.highlighter(bufnr, ft)
|
||||
end))
|
||||
end
|
||||
if opts.callback then opts.callback(bufnr) end
|
||||
putils.highlighter(bufnr, ft)
|
||||
end))
|
||||
end
|
||||
end)
|
||||
else
|
||||
if opts.callback then opts.callback(bufnr) end
|
||||
if opts.callback then
|
||||
if vim.in_fast_event() then
|
||||
vim.schedule(function() opts.callback(bufnr) end)
|
||||
else
|
||||
opts.callback(bufnr)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -112,8 +120,10 @@ previewers.new_buffer_previewer = function(opts)
|
||||
end
|
||||
|
||||
local function set_bufnr(self, value)
|
||||
if get_bufnr(self) then table.insert(old_bufs, get_bufnr(self)) end
|
||||
if self.state then self.state.bufnr = value end
|
||||
if self.state then
|
||||
self.state.bufnr = value
|
||||
table.insert(old_bufs, value)
|
||||
end
|
||||
end
|
||||
|
||||
local function get_bufnr_by_bufname(self, value)
|
||||
@@ -122,8 +132,12 @@ previewers.new_buffer_previewer = function(opts)
|
||||
end
|
||||
|
||||
local function set_bufname(self, value)
|
||||
if get_bufnr(self) then bufname_table[value] = get_bufnr(self) end
|
||||
if self.state then self.state.bufname = value end
|
||||
if self.state then
|
||||
self.state.bufname = value
|
||||
if value then
|
||||
bufname_table[value] = get_bufnr(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function opts.setup(self)
|
||||
|
||||
@@ -72,9 +72,11 @@ end
|
||||
--- It requires you to specify one table entry `get_command(entry, status)`.
|
||||
--- This `get_command` function has to return the terminal command that will be
|
||||
--- executed for each entry. Example:
|
||||
--- <pre>
|
||||
--- get_command = function(entry, status)
|
||||
--- return { 'bat', entry.path }
|
||||
--- end
|
||||
--- </pre>
|
||||
---
|
||||
--- It's an easy way to get your first previewer going and it integrates well
|
||||
--- with `bat` and `less`. Providing out of the box scrolling if the command
|
||||
|
||||
@@ -38,8 +38,7 @@ utils.job_maker = function(cmd, bufnr, opts)
|
||||
on_exit = vim.schedule_wrap(function(j)
|
||||
if not vim.api.nvim_buf_is_valid(bufnr) then return end
|
||||
if opts.mode == "append" then
|
||||
local count = vim.api.nvim_buf_line_count(bufnr)
|
||||
vim.api.nvim_buf_set_lines(bufnr, count, -1, false, j:result())
|
||||
vim.api.nvim_buf_set_lines(bufnr, -1, -1, false, j:result())
|
||||
elseif opts.mode == "insert" then
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, j:result())
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user