fix: preview title key and a bug with dynamic_title (#1350)

This commit is contained in:
Simon Hauser
2021-10-20 16:23:26 +02:00
committed by GitHub
parent adfbd616c6
commit a0835edd86
5 changed files with 37 additions and 60 deletions

View File

@@ -277,8 +277,6 @@ previewers.new_buffer_previewer = function(opts)
local opt_setup = opts.setup
local opt_teardown = opts.teardown
local opt_title = opts.title
local opt_dyn_title = opts.dyn_title
local old_bufs = {}
local bufname_table = {}
@@ -316,24 +314,6 @@ previewers.new_buffer_previewer = function(opts)
end
end
function opts.title(self)
if opt_title then
if type(opt_title) == "function" then
return opt_title(self)
else
return opt_title
end
end
return "Preview"
end
function opts.dyn_title(self, entry)
if opt_dyn_title then
return opt_dyn_title(self, entry)
end
return "Preview"
end
function opts.setup(self)
local state = {}
if opt_setup then

View File

@@ -1,13 +1,25 @@
local Previewer = {}
Previewer.__index = Previewer
local force_function_wrap = function(value)
if value ~= nil then
if type(value) ~= "function" then
return function()
return tostring(value)
end
else
return value
end
end
end
function Previewer:new(opts)
opts = opts or {}
return setmetatable({
state = nil,
_title_fn = opts.title,
_dyn_title_fn = opts.dyn_title,
_title_fn = force_function_wrap(opts.title),
_dyn_title_fn = force_function_wrap(opts.dyn_title),
_setup_func = opts.setup,
_teardown_func = opts.teardown,
_send_input = opts.send_input,
@@ -32,18 +44,16 @@ function Previewer:preview(entry, status)
return self:preview_fn(entry, status)
end
function Previewer:title()
if self._title_fn then
return self:_title_fn()
end
return "Preview"
end
function Previewer:dynamic_title(entry)
if self._title_fn then
function Previewer:title(entry, dynamic)
if dynamic == true and self._dyn_title_fn ~= nil then
if entry == nil then
return nil
end
return self:_dyn_title_fn(entry)
end
return "Preview"
if self._title_fn ~= nil then
return self:_title_fn()
end
end
function Previewer:teardown()

View File

@@ -118,8 +118,6 @@ previewers.new_termopen_previewer = function(opts)
local opt_setup = opts.setup
local opt_teardown = opts.teardown
local opt_title = opts.title
local opt_dyn_title = opts.dyn_title
local old_bufs = {}
@@ -155,24 +153,6 @@ previewers.new_termopen_previewer = function(opts)
end
end
function opts.title(self)
if opt_title then
if type(opt_title) == "function" then
return opt_title(self)
else
return opt_title
end
end
return "Preview"
end
function opts.dyn_title(self, entry)
if opt_dyn_title then
return opt_dyn_title(self, entry)
end
return "Preview"
end
function opts.setup(self)
local state = {}
if opt_setup then