File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,15 @@ use {
123123 popup_border_style = " rounded" ,
124124 enable_git_status = true ,
125125 enable_diagnostics = true ,
126+ sort_case_insensitive = false , -- used when sorting files and directories in the tree
127+ sort_function = nil , -- use a custom function for sorting files and directories in the tree
128+ -- sort_function = function (a,b)
129+ -- if a.type == b.type then
130+ -- return a.path > b.path
131+ -- else
132+ -- return a.type > b.type
133+ -- end
134+ -- end , -- this sorts files and directories descendantly
126135 default_component_configs = {
127136 container = {
128137 enable_character_fade = true
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ local config = {
2525 -- set to -1 to disable the resize timer entirely
2626 -- -- NOTE: this will speed up to 50 ms for 1 second following a resize
2727 sort_case_insensitive = false , -- used when sorting files and directories in the tree
28+ sort_function = nil , -- uses a custom function for sorting files and directories in the tree
2829 use_popups_for_input = true , -- If false, inputs will use vim.ui.input() instead of custom floats.
2930 use_default_mappings = true ,
3031 --
Original file line number Diff line number Diff line change @@ -22,10 +22,29 @@ local function sort_items_case_insensitive(a, b)
2222 end
2323end
2424
25+ local function sort_function_is_valid (func )
26+ if func == nil then
27+ return false
28+ end
29+
30+ local a = { type = " dir" , path = " foo" }
31+ local b = { type = " dir" , path = " baz" }
32+
33+ local success , result = pcall (func , a , b )
34+ if success and type (result ) == " boolean" then
35+ return true
36+ end
37+
38+ log .error (" sort function isn't valid " , result )
39+ return false
40+ end
41+
2542local function deep_sort (tbl , sort_func )
2643 if sort_func == nil then
2744 local config = require (" neo-tree" ).config
28- if config .sort_case_insensitive then
45+ if sort_function_is_valid (config .sort_function ) then
46+ sort_func = config .sort_function
47+ elseif config .sort_case_insensitive then
2948 sort_func = sort_items_case_insensitive
3049 else
3150 sort_func = sort_items
You can’t perform that action at this time.
0 commit comments