Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ use {
popup_border_style = "rounded",
enable_git_status = true,
enable_diagnostics = true,
sort_case_insensitive = false, -- used when sorting files and directories in the tree
sort_function = nil , -- use a custom function for sorting files and directories in the tree
-- sort_function = function (a,b)
-- if a.type == b.type then
-- return a.path > b.path
-- else
-- return a.type > b.type
-- end
-- end , -- this sorts files and directories descendantly
default_component_configs = {
container = {
enable_character_fade = true
Expand Down
1 change: 1 addition & 0 deletions lua/neo-tree/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ local config = {
-- set to -1 to disable the resize timer entirely
-- -- NOTE: this will speed up to 50 ms for 1 second following a resize
sort_case_insensitive = false, -- used when sorting files and directories in the tree
sort_function = nil , -- uses a custom function for sorting files and directories in the tree
use_popups_for_input = true, -- If false, inputs will use vim.ui.input() instead of custom floats.
use_default_mappings = true,
--
Expand Down
21 changes: 20 additions & 1 deletion lua/neo-tree/sources/common/file-items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,29 @@ local function sort_items_case_insensitive(a, b)
end
end

local function sort_function_is_valid(func)
if func == nil then
return false
end

local a = { type = "dir", path = "foo" }
local b = { type = "dir", path = "baz" }

local success, result = pcall(func, a, b)
if success and type(result) == "boolean" then
return true
end

log.error("sort function isn't valid ", result)
return false
end

local function deep_sort(tbl, sort_func)
if sort_func == nil then
local config = require("neo-tree").config
if config.sort_case_insensitive then
if sort_function_is_valid(config.sort_function) then
sort_func = config.sort_function
elseif config.sort_case_insensitive then
sort_func = sort_items_case_insensitive
else
sort_func = sort_items
Expand Down