Skip to content

Commit a75b1bf

Browse files
committed
feat: add sort_case_insensitive option, close #203
1 parent b500daa commit a75b1bf

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

doc/neo-tree.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,11 @@ wish to remove a default mapping without overriding it with your own function,
361361
assign it the the string "none". This will cause it to be skipped and allow any
362362
existing global mappings to work.
363363

364-
Run |NeoTreePasteConfig| to dump the fully commented default config in your
365-
current file. Even if you don't want to use that config as your starting point,
366-
you still may want to dump it to a blank .lua file just to read it as
367-
documentation. SOME OPTIONS ARE ONLY DOCUMENTED IN THE DEFAULT CONFIG!
364+
NOTE: SOME OPTIONS ARE ONLY DOCUMENTED IN THE DEFAULT CONFIG!~
365+
Run `:lua require("neo-tree").paste_default_config()` to dump the fully
366+
commented default config in your current file. Even if you don't want to use
367+
that config as your starting point, you still may want to dump it to a blank
368+
lua file just to read it as documentation.
368369

369370

370371
FILTERED ITEMS *neo-tree-filtered-items*

lua/neo-tree/defaults.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local config = {
1111
enable_git_status = true,
1212
git_status_async = true,
1313
open_files_in_last_window = true, -- false = open files in top left window
14+
sort_case_insensitive = false, -- used when sorting files and directories in the tree
1415
log_level = "info", -- "trace", "debug", "info", "warn", "error", "fatal"
1516
log_to_file = false, -- true, false, "/path/to/file.log", use :NeoTreeLogs to show the file
1617
--

lua/neo-tree/sources/common/file-items.lua

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,27 @@ local function sort_items(a, b)
1212
end
1313
end
1414

15-
local function deep_sort(tbl)
16-
table.sort(tbl, sort_items)
15+
local function sort_items_case_insensitive(a, b)
16+
if a.type == b.type then
17+
return a.path:lower() < b.path:lower()
18+
else
19+
return a.type < b.type
20+
end
21+
end
22+
23+
local function deep_sort(tbl, sort_func)
24+
if sort_func == nil then
25+
local config = require("neo-tree").config
26+
if config.sort_case_insensitive then
27+
sort_func = sort_items_case_insensitive
28+
else
29+
sort_func = sort_items
30+
end
31+
end
32+
table.sort(tbl, sort_func)
1733
for _, item in pairs(tbl) do
1834
if item.type == "directory" then
19-
deep_sort(item.children)
35+
deep_sort(item.children, sort_func)
2036
end
2137
end
2238
end

0 commit comments

Comments
 (0)