Skip to content

Commit 27bef83

Browse files
committed
feat(pickers): add an option to resume and select the entry
1 parent 2eca9ba commit 27bef83

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

doc/telescope.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,9 @@ builtin.resume({opts}) *telescope.builtin.resume()*
12511251
Options: ~
12521252
{cache_index} (number) what picker to resume, where 1 denotes most
12531253
recent (default: 1)
1254+
{select_pos} (number) select the entry that position is specified
1255+
by this value and do `actions.select_default`
1256+
(default: nil)
12541257

12551258

12561259
builtin.pickers({opts}) *telescope.builtin.pickers()*

lua/telescope/builtin/__internal.lua

+12
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ internal.resume = function(opts)
148148
})
149149
return
150150
end
151+
if opts.select_pos then
152+
if picker.manager:num_results() <= math.abs(opts.select_pos) then
153+
utils.notify("builtin.resume", {
154+
msg = string.format("The picker has less entries than supplied pos: %d", opts.select_pos),
155+
level = "ERROR",
156+
})
157+
return
158+
end
159+
opts._select_pos = opts.select_pos
160+
opts.select_pos = nil
161+
end
162+
151163
-- reset layout strategy and get_window_options if default as only one is valid
152164
-- and otherwise unclear which was actually set
153165
if picker.layout_strategy == conf.layout_strategy then

lua/telescope/pickers.lua

+6
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ function Picker:new(opts)
324324

325325
cache_picker = config.resolve_table_opts(opts.cache_picker, vim.deepcopy(config.values.cache_picker)),
326326

327+
_select_pos = opts._select_pos,
328+
327329
__scrolling_limit = tonumber(vim.F.if_nil(opts.temp__scrolling_limit, 250)),
328330

329331
__locations_input = vim.F.if_nil(opts.__locations_input, false),
@@ -1708,6 +1710,10 @@ function Picker:_resume_picker()
17081710
vim.cmd "do User TelescopeResumePost"
17091711
end)
17101712
end
1713+
if self._select_pos then
1714+
self:move_selection(self._select_pos)
1715+
vim.schedule_wrap(actions.select_default)(self.prompt_bufnr)
1716+
end
17111717
end
17121718
-- if text changed, required to set anew to restart finder; otherwise hl and selection
17131719
if self.cache_picker.cached_prompt ~= self.default_text then

0 commit comments

Comments
 (0)