@@ -1424,27 +1424,38 @@ end
14241424
14251425internal .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 ()
14501461end
0 commit comments