Skip to content

Commit

Permalink
feat(jumplist): add select_last_used option
Browse files Browse the repository at this point in the history
just like buffers picker has select_current option (#2918)
  • Loading branch information
atusy committed Feb 25, 2024
1 parent 2e1e382 commit fb64f64
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
6 changes: 4 additions & 2 deletions doc/telescope.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1537,8 +1537,10 @@ builtin.jumplist({opts}) *telescope.builtin.jumplist()*
{opts} (table) options to pass to the picker

Options: ~
{show_line} (boolean) show results text (default: true)
{trim_text} (boolean) trim results text (default: false)
{show_line} (boolean) show results text (default: true)
{trim_text} (boolean) trim results text (default: false)
{select_last_used} (boolean) select last used jump position
(default: false)


builtin.lsp_references({opts}) *telescope.builtin.lsp_references()*
Expand Down
31 changes: 21 additions & 10 deletions lua/telescope/builtin/__internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1424,27 +1424,38 @@ end

internal.jumplist = function(opts)
opts = opts or {}
local jumplist = vim.fn.getjumplist()[1]

-- reverse the list
local sorted_jumplist = {}
for i = #jumplist, 1, -1 do
if vim.api.nvim_buf_is_valid(jumplist[i].bufnr) then
jumplist[i].text = vim.api.nvim_buf_get_lines(jumplist[i].bufnr, jumplist[i].lnum - 1, jumplist[i].lnum, false)[1]
or ""
table.insert(sorted_jumplist, jumplist[i])
local jumplist = vim.fn.getjumplist()
local locations = jumplist[1]
local lastidx = jumplist[2] + 1

-- reverse the list and determine the defeault selection
local sorted_locations = {}
local default_selection_idx = 1
for i = #locations, 1, -1 do
if vim.api.nvim_buf_is_valid(locations[i].bufnr) then
locations[i].text = vim.api.nvim_buf_get_lines(
locations[i].bufnr,
locations[i].lnum - 1,
locations[i].lnum,
false
)[1] or ""
table.insert(sorted_locations, locations[i])
if opts.select_last_used and i == lastidx then
default_selection_idx = #sorted_locations
end
end
end

pickers
.new(opts, {
prompt_title = "Jumplist",
finder = finders.new_table {
results = sorted_jumplist,
results = sorted_locations,
entry_maker = make_entry.gen_from_quickfix(opts),
},
previewer = conf.qflist_previewer(opts),
sorter = conf.generic_sorter(opts),
default_selection_index = default_selection_idx,
})
:find()
end
Expand Down

0 comments on commit fb64f64

Please sign in to comment.