Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jumplist): add select_last_used option (closes #2947) #2948

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions doc/telescope.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1540,8 +1540,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
Loading