feat: allow a callback to be called on on_lines update (for filtering tags from query text) (#455)

* allow a callback to be called on on_lines update

* .

* remove unused _filter_marker var

* nit: Move to table and implement 'close'

Co-authored-by: TJ DeVries <devries.timothyj@gmail.com>
This commit is contained in:
Senghan Bright
2021-01-28 22:39:05 +01:00
committed by GitHub
parent 5995a8be8f
commit 9d4670c748
2 changed files with 15 additions and 2 deletions

View File

@@ -11,6 +11,8 @@ local _callable_obj = function()
obj.__index = obj obj.__index = obj
obj.__call = function(t, ...) return t:_find(...) end obj.__call = function(t, ...) return t:_find(...) end
obj.close = function() end
return obj return obj
end end
@@ -33,7 +35,7 @@ local JobFinder = _callable_obj()
function JobFinder:new(opts) function JobFinder:new(opts)
opts = opts or {} opts = opts or {}
> assert(not opts.results, "`results` should be used with finder.new_table") assert(not opts.results, "`results` should be used with finder.new_table")
assert(not opts.static, "`static` should be used with finder.new_oneshot_job") assert(not opts.static, "`static` should be used with finder.new_oneshot_job")
local obj = setmetatable({ local obj = setmetatable({

View File

@@ -76,6 +76,7 @@ function Picker:new(opts)
default_text = opts.default_text, default_text = opts.default_text,
get_status_text = get_default(opts.get_status_text, config.values.get_status_text), get_status_text = get_default(opts.get_status_text, config.values.get_status_text),
_on_input_filter_cb = opts.on_input_filter_cb or function() end,
finder = opts.finder, finder = opts.finder,
sorter = opts.sorter, sorter = opts.sorter,
@@ -445,7 +446,17 @@ function Picker:find()
return return
end end
local prompt = self:_get_prompt() local original_prompt = self:_get_prompt()
local on_input_result = self._on_input_filter_cb(original_prompt) or {}
local prompt = on_input_result.prompt or original_prompt
local finder = on_input_result.updated_finder
if finder then
self.finder:close()
self.finder = finder
end
if self.sorter then if self.sorter then
self.sorter:_start(prompt) self.sorter:_start(prompt)
end end