Skip to content

Commit

Permalink
fix: telescope picker shows symbols in order (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Oct 25, 2022
1 parent 4d6e283 commit 848779f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lua/aerial/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,20 @@ M.throttle = function(func, opts)
end
end

---@generic T : any
---@param tbl T[]
---@return T[]
M.tbl_reverse = function(tbl)
local len = #tbl
for i = 1, math.floor(len / 2) do
local j = len - i + 1
local swp = tbl[i]
tbl[i] = tbl[j]
tbl[j] = swp
end
return tbl
end

M.get_filetypes = config.get_filetypes

return M
5 changes: 5 additions & 0 deletions lua/telescope/_extensions/aerial.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local backends = require("aerial.backends")
local config = require("aerial.config")
local data = require("aerial.data")
local util = require("aerial.util")

local conf = require("telescope.config").values
local entry_display = require("telescope.pickers.entry_display")
Expand Down Expand Up @@ -88,6 +89,10 @@ local function aerial_picker(opts)
end
end
end

-- Reverse the symbols so they have the same top-to-bottom order as in the file
util.tbl_reverse(results)
default_selection_index = #results - (default_selection_index - 1)
pickers
.new(opts, {
prompt_title = "Document Symbols",
Expand Down

0 comments on commit 848779f

Please sign in to comment.