feat: clear previewer if no item is selected (#2004)
This commit is contained in:
committed by
Simon Hauser
parent
bef86acb6c
commit
25b1bc8f17
@@ -965,6 +965,9 @@ function Picker:set_selection(row)
|
||||
state.set_global_key("selected_entry", entry)
|
||||
|
||||
if not entry then
|
||||
-- also refresh previewer when there is no entry selected, so the preview window is cleared
|
||||
self._selection_entry = entry
|
||||
self:refresh_previewer()
|
||||
return
|
||||
end
|
||||
|
||||
@@ -1068,10 +1071,6 @@ end
|
||||
--- Refresh the previewer based on the current `status` of the picker
|
||||
function Picker:refresh_previewer()
|
||||
local status = state.get_status(self.prompt_bufnr)
|
||||
if not self._selection_entry then
|
||||
-- if selection_entry is nil there is nothing to be previewed
|
||||
return
|
||||
end
|
||||
if self.previewer and status.preview_win and a.nvim_win_is_valid(status.preview_win) then
|
||||
self:_increment "previewed"
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
local utils = require "telescope.utils"
|
||||
|
||||
local Previewer = {}
|
||||
Previewer.__index = Previewer
|
||||
|
||||
@@ -25,11 +27,19 @@ function Previewer:new(opts)
|
||||
_send_input = opts.send_input,
|
||||
_scroll_fn = opts.scroll_fn,
|
||||
preview_fn = opts.preview_fn,
|
||||
_empty_bufnr = nil,
|
||||
}, Previewer)
|
||||
end
|
||||
|
||||
function Previewer:preview(entry, status)
|
||||
if not entry then
|
||||
if not self._empty_bufnr then
|
||||
self._empty_bufnr = vim.api.nvim_create_buf(false, true)
|
||||
end
|
||||
|
||||
if vim.api.nvim_buf_is_valid(self._empty_bufnr) then
|
||||
vim.api.nvim_win_set_buf(status.preview_win, self._empty_bufnr)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
@@ -47,7 +57,11 @@ end
|
||||
function Previewer:title(entry, dynamic)
|
||||
if dynamic == true and self._dyn_title_fn ~= nil then
|
||||
if entry == nil then
|
||||
return nil
|
||||
if self._title_fn ~= nil then
|
||||
return self:_title_fn()
|
||||
else
|
||||
return ""
|
||||
end
|
||||
end
|
||||
return self:_dyn_title_fn(entry)
|
||||
end
|
||||
@@ -57,6 +71,9 @@ function Previewer:title(entry, dynamic)
|
||||
end
|
||||
|
||||
function Previewer:teardown()
|
||||
if self._empty_bufnr then
|
||||
utils.buf_delete(self._empty_bufnr)
|
||||
end
|
||||
if self._teardown_func then
|
||||
self:_teardown_func()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user