feat(pickers): add an option to resume and select the entry

This commit is contained in:
delphinus
2025-01-03 23:41:30 +09:00
parent 415af52339
commit bcdfac0d0d
3 changed files with 19 additions and 0 deletions
+12
View File
@@ -148,6 +148,18 @@ internal.resume = function(opts)
})
return
end
if opts.select_pos then
if picker.manager:num_results() <= math.abs(opts.select_pos) then
utils.notify("builtin.resume", {
msg = string.format("The picker has less entries than supplied pos: %d", opts.select_pos),
level = "ERROR",
})
return
end
opts._select_pos = opts.select_pos
opts.select_pos = nil
end
-- reset layout strategy and get_window_options if default as only one is valid
-- and otherwise unclear which was actually set
if picker.layout_strategy == conf.layout_strategy then
+1
View File
@@ -249,6 +249,7 @@ builtin.builtin = require_on_exported_call("telescope.builtin.__internal").built
--- - Requires `cache_picker` in setup or when having invoked pickers, see |telescope.defaults.cache_picker|
---@param opts table: options to pass to the picker
---@field cache_index number: what picker to resume, where 1 denotes most recent (default: 1)
---@field select_pos number: select the entry that position is specified by this value and do `actions.select_default` (default: nil)
builtin.resume = require_on_exported_call("telescope.builtin.__internal").resume
--- Opens a picker over previously cached pickers in their preserved states (incl. multi selections)
+6
View File
@@ -324,6 +324,8 @@ function Picker:new(opts)
cache_picker = config.resolve_table_opts(opts.cache_picker, vim.deepcopy(config.values.cache_picker)),
_select_pos = opts._select_pos,
__scrolling_limit = tonumber(vim.F.if_nil(opts.temp__scrolling_limit, 250)),
__locations_input = vim.F.if_nil(opts.__locations_input, false),
@@ -1708,6 +1710,10 @@ function Picker:_resume_picker()
vim.cmd "do User TelescopeResumePost"
end)
end
if self._select_pos then
self:move_selection(self._select_pos)
vim.schedule_wrap(actions.select_default)(self.prompt_bufnr)
end
end
-- if text changed, required to set anew to restart finder; otherwise hl and selection
if self.cache_picker.cached_prompt ~= self.default_text then