Skip to content

Commit fb64f64

Browse files
committed
feat(jumplist): add select_last_used option
just like buffers picker has select_current option (#2918)
1 parent 2e1e382 commit fb64f64

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

doc/telescope.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,8 +1537,10 @@ builtin.jumplist({opts}) *telescope.builtin.jumplist()*
15371537
{opts} (table) options to pass to the picker
15381538

15391539
Options: ~
1540-
{show_line} (boolean) show results text (default: true)
1541-
{trim_text} (boolean) trim results text (default: false)
1540+
{show_line} (boolean) show results text (default: true)
1541+
{trim_text} (boolean) trim results text (default: false)
1542+
{select_last_used} (boolean) select last used jump position
1543+
(default: false)
15421544

15431545

15441546
builtin.lsp_references({opts}) *telescope.builtin.lsp_references()*

lua/telescope/builtin/__internal.lua

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,27 +1424,38 @@ end
14241424

14251425
internal.jumplist = function(opts)
14261426
opts = opts or {}
1427-
local jumplist = vim.fn.getjumplist()[1]
1428-
1429-
-- reverse the list
1430-
local sorted_jumplist = {}
1431-
for i = #jumplist, 1, -1 do
1432-
if vim.api.nvim_buf_is_valid(jumplist[i].bufnr) then
1433-
jumplist[i].text = vim.api.nvim_buf_get_lines(jumplist[i].bufnr, jumplist[i].lnum - 1, jumplist[i].lnum, false)[1]
1434-
or ""
1435-
table.insert(sorted_jumplist, jumplist[i])
1427+
local jumplist = vim.fn.getjumplist()
1428+
local locations = jumplist[1]
1429+
local lastidx = jumplist[2] + 1
1430+
1431+
-- reverse the list and determine the defeault selection
1432+
local sorted_locations = {}
1433+
local default_selection_idx = 1
1434+
for i = #locations, 1, -1 do
1435+
if vim.api.nvim_buf_is_valid(locations[i].bufnr) then
1436+
locations[i].text = vim.api.nvim_buf_get_lines(
1437+
locations[i].bufnr,
1438+
locations[i].lnum - 1,
1439+
locations[i].lnum,
1440+
false
1441+
)[1] or ""
1442+
table.insert(sorted_locations, locations[i])
1443+
if opts.select_last_used and i == lastidx then
1444+
default_selection_idx = #sorted_locations
1445+
end
14361446
end
14371447
end
14381448

14391449
pickers
14401450
.new(opts, {
14411451
prompt_title = "Jumplist",
14421452
finder = finders.new_table {
1443-
results = sorted_jumplist,
1453+
results = sorted_locations,
14441454
entry_maker = make_entry.gen_from_quickfix(opts),
14451455
},
14461456
previewer = conf.qflist_previewer(opts),
14471457
sorter = conf.generic_sorter(opts),
1458+
default_selection_index = default_selection_idx,
14481459
})
14491460
:find()
14501461
end

0 commit comments

Comments
 (0)