Skip to content

Commit fd2332a

Browse files
authored
feat: case sensitive sorter (#1198)
1 parent eeb842c commit fd2332a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

doc/nvim-tree-lua.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ Here is a list of the options available in the setup call:
253253

254254
*nvim-tree.sort_by*
255255
- |sort_by|: changes how files within the same directory are sorted. can be
256-
one of 'name' | 'modification_time'
256+
one of 'name' | 'case_sensitive' | 'modification_time'.
257257
type: `string`
258258
default: `"name"`
259259

lua/nvim-tree/explorer/sorters.lua

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function M.merge_sort(t, comparator)
7575
split_merge(t, 1, #t, comparator)
7676
end
7777

78-
function M.node_comparator_name(a, b)
78+
local function node_comparator_name_ignorecase_or_not(a, b, ignorecase)
7979
if not (a and b) then
8080
return true
8181
end
@@ -85,7 +85,19 @@ function M.node_comparator_name(a, b)
8585
return false
8686
end
8787

88-
return a.name:lower() <= b.name:lower()
88+
if ignorecase then
89+
return a.name:lower() <= b.name:lower()
90+
else
91+
return a.name <= b.name
92+
end
93+
end
94+
95+
function M.node_comparator_name_case_sensisive(a, b)
96+
return node_comparator_name_ignorecase_or_not(a, b, false)
97+
end
98+
99+
function M.node_comparator_name_ignorecase(a, b)
100+
return node_comparator_name_ignorecase_or_not(a, b, true)
89101
end
90102

91103
function M.node_comparator_modification_time(a, b)
@@ -116,8 +128,10 @@ function M.setup(opts)
116128
M.sort_by = opts.sort_by
117129
if M.sort_by == "modification_time" then
118130
M.node_comparator = M.node_comparator_modification_time
131+
elseif M.sort_by == "case_sensitive" then
132+
M.node_comparator = M.node_comparator_name_case_sensisive
119133
else
120-
M.node_comparator = M.node_comparator_name
134+
M.node_comparator = M.node_comparator_name_ignorecase
121135
end
122136
end
123137

0 commit comments

Comments
 (0)