Skip to content

feat: Mixin Sorter (#1565) Self Solved #1566

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

Merged
merged 13 commits into from
Sep 18, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: user_index based sorting ( create index )
for performance, create index once,
using index to re-ordering
  • Loading branch information
p4r4d0xb0x committed Sep 16, 2022
commit 7492886ead62fef636dd180f60ec1d71b2e723a9
27 changes: 10 additions & 17 deletions lua/nvim-tree/explorer/sorters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,25 @@ function M.merge_sort(t, comparator)

if type(user_order) == "table" then
-- do merge sort for prevent memory exceed
local user_index = {}
for k, v in pairs(user_order) do
if user_index[v] == nil then
user_index[v] = k
end
end
local mini_comparator = function(a, b)
local a_index = vim.tbl_indexof(user_order, a.absolute_path)
local b_index = vim.tbl_indexof(user_order, b.absolute_path)
if a_index == -1 then
local a_index = user_index[a.absolute_path]
local b_index = user_index[b.absolute_path]
if a_index == -1 or a_index == nil then
a_index = 9999999999
end
if b_index == -1 then
if b_index == -1 or a_index == nil then
b_index = 9999999999
end
return a_index < b_index
end

split_merge(t, 1, #t, mini_comparator) -- sort by user order

-- for _, n in ipairs(user_order) do
-- for i = 1, #user_order, 1 do
-- for j = 1, #t, 1 do
-- if t[j] and t[j].absolute_path == user_order[i] then
-- local tmp = t[i]
-- t[i] = t[j]
-- t[j] = tmp
-- break
-- end
-- end
-- end -- reorder the list according to the user order
-- end
end
else
if not comparator then
Expand Down